Make sure your Spotify application is up and running for this to work properly.
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
Popularity: 4%
GameKit giving me a BT status of not available?
I’ve been using GameKit to connect an app together with different iOS devices. Suddenly know when I run the app and I choose to connect by bringing up the GKPeerPickerController, I get this in the console:
- BTM: attaching to BTServer
- <<< Session >>> +[GKBluetoothSupport _determineBluetoothStatus]: BT not available – try again later.
- BTM: posting notification BluetoothAvailabilityChangedNotification
I have no idea why this is happening as BT is enabled on the iOS devices in question. This is using the latest XCode 4 which I was using before without any problems. The code is pretty simple…
-(IBAction) btnConnect:(id) sender {
picker = [[GKPeerPickerController alloc] init];
picker.delegate = self;
picker.connectionTypesMask = GKPeerPickerConnectionTypeNearby;
[connect setHidden:YES];
[disconnect setHidden:NO];
[picker show];
}
Since I am using the picker I am not declaring a session myself. It should just work, but I get the BT not available error. This is on various iOS devices. I have played with the compiler (which one is being used) to no avail. I am wondering what might cause this behavior because it’s blocking me pretty badly at the moment.
Any ideas?
Update (May 17, 2011 @8:41 AM EDT):
While I still get that strange status, what I did to see if it would still work was this: turn OFF Bluetooth on the iOS device, then ran the application, and of course when the picker is called up and BT is off, you’re prompted to enable BT. When I did that this would be able to connect…
- BTM: attaching to BTServer
- <<< Session >>> +[GKBluetoothSupport _determineBluetoothStatus]: BT not available – try again later.
- BTM: posting notification BluetoothAvailabilityChangedNotification
- BTM: received BT_LOCAL_DEVICE_POWER_STATE_CHANGED event
- BTM: posting notification BluetoothPowerChangedNotification
- BTM: Adding new device 0x192b60 Verizon iPhone 24:AB:81:E3:63:BB 0xf51c0016
- BTM: _btServiceEventCallback: service = 0×800 eventType = 0 event = 1 result = 0
- BTM: _btServiceEventCallback: service = 0×800 eventType = 0 event = 11 result = 0
- BTM: received BT_SERVICE_CONNECTION_RESULT event with 1 currently connected services
- BTM: posting notification BluetoothDeviceConnectSuccessNotification
- BTM: received BT_LOCAL_DEVICE_CONNECTION_STATUS_CHANGED event
- BTM: posting notification BluetoothConnectionStatusChangedNotification
This is at least a work-around even though I have no idea why it’s required all of the sudden.
Popularity: 5%
