Search code examples
iphonebluetoothwirelessgamekit

How to specify Wireless or Bluetooth in GameKit when using my own custom interface


I've decided to implement my own interface for connecting two devices running my game, as opposed to using the GKPeerPickerController. This is actually working quite well. But I just realised that in my creating of the GKSession I'm not actually specifying whether the connection should be Wireless or Bluetooth. I have an option in my interface to let the user specify which connection method they'd like to use. How do I tell GKSession whether I want it to connect via Bluetooth or Wireless?

I think what is currently happening is that it defaults to Wireless if wireless is enabled otherwise it uses Bluetooth. But I'd like to let the user specify which connection method, is this possible?

Thanks, Donna


Solution

  • As far as I know, you can't do this yourself. That's what the GKPeerPickerController is for. It defaults to setting up connections over BlueTooth, but you can also add the second mask so it allows the user to pick their protocol. Basically what I've been doing is setting the mask to allow the user to pick either bluetooth or "online" (wifi):

    _picker.connectionTypesMask = GKPeerPickerConnectionTypeNearby|GKPeerPickerConnectionTypeOnline;
    

    That then if they pick online, dismiss the peer picker and continue implementing your custom interface. The session should be created in the same way as far as I know. It's not super well documented :/