GameKit: Connecting different applications

For the past few days I was struggling with GameKit – notably getting it working properly. I was told in a few places that applications connecting over GameKit Bluetooth needed to have the same bundle ID. Which on the surface makes sense… normally it’s used to connect the same game in a multi-player type of situation. However, that was wrong and I needed two different applications to connect over something and I had chosen GameKit.

Normally when using a GKPeerPickerController the session is a default – and uses the bundle ID. Hence if you had two different applications trying to connect they wouldn’t show up in the picker. However using a delegate method (GKPeerPickerControllerDelegate) you’re able to supply your own sessionID. That means that two different applications CAN see one another and create a connection. The didConnectPeer is ignored and the sessionID you provide will be used.

- (GKSession *)peerPickerController:(GKPeerPickerController *)picker sessionForConnectionType:(GKPeerPickerConnectionType)type
    if(currentSession == nil){
        currentSession = [[GKSession alloc] initWithSessionID:@"Foo" displayName:@"Hey There" sessionMode:GKSessionModePeer];
        currentSession.delegate = self;
    return currentSession;

Now when the apps choose to connect, the string “Hey There” will be presented in the respective pickers and the applications will connect with the sessionID “Foo”. You’re free to have them communicate back and forth… which is awesome because I was blocked until I found this. I almost opted for Bonjour and socket streaming. I may still, but at least I have BT working between the two applications.

A woot moment for moi ;)

Related Posts Plugin for WordPress, Blogger...

Leave a Reply

Your email address will not be published. Required fields are marked *

eight − 4 =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>