views:

214

answers:

2

Hi,

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

A: 

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 :/

Typeoneerror
+1  A: 

To to do the selection, you need an interface that asks the user whether they want to use the network or bluetooth. If the latter, it can jump to a peerpickercontroller or implement GK calls itself. For the former, you have to dump GK and code it all manually.

This is a pretty complex topic, involving setting up a Bonjour stream and listening objects on either side. It works completely outside of GameKit, which is Bluetooth only.

There is a very good chapter on how to implement the networking protocols in Apress' More iPhone 3 Development - Chapter 9. Its a very good book and worth it for that chapter alone is you are trying to do this. It explains all the issues very well and walks you through a functional example game.

fogelbaby