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

I decided to implement my own interface for connecting two devices running my game, as opposed to using GKPeerPickerController. It works very well. But I just realized that when I created the GKSession, I did not actually indicate whether the connection should be Wireless or Bluetooth. I have an option in my interface to let the user specify which connection method they would like to use. How do I tell GKSession if I want it to connect via Bluetooth or Wireless?

I think that what is currently happening is that the default is Wireless, if wireless is turned on, otherwise Bluetooth is used. But I would like the user to indicate which connection method, is this possible?

Thanks Donna

+4
source share
2 answers

As far as I know, you cannot do it yourself. This requires the GKPeerPickerController. It defaults to configuring connections through BlueTooth, but you can also add a second mask so that the user can select their protocol. Basically what I did was set up a mask that allows the user to choose either Bluetooth or β€œonline” (wifi):

_picker.connectionTypesMask = GKPeerPickerConnectionTypeNearby|GKPeerPickerConnectionTypeOnline; 

So then, if they chose online, release the peer picker program and continue implementing your user interface. A session should be created in the same way as I know. This is not well documented: /

+2
source

To make a choice, you need an interface that asks the user if they want to use the network or Bluetooth. If the latter, it can go to the peerpickercontroller or implement GK calls. For the first, you need to reset the GK and program it all manually.

This is a rather complicated topic related to setting up the Bonjour stream and listening objects on both sides. It works completely outside of GameKit, which is only Bluetooth.

There is a very good chapter on how to implement network protocols in Apress' More iPhone 3 Development - Chapter 9. Its a very good book and is only worth it for this chapter, you are trying to do it. He very well explains all the problems and guides you through a functional sample game.

+1
source

Source: https://habr.com/ru/post/1305187/


All Articles