Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I correctly setup a GKSession (Bluetooth) on iOS 6.1
    text
    copied!<p>I am having an issue with getting a GKSession to work. Below is my code that is executed when a specific button is pressed.</p> <pre><code>GKSession *session; if (connectButtonHasBeenPressed == false) { NSLog(@"connectToBluetoothDevice has been called"); connectButtonHasBeenPressed = true; GKSession *session = [[GKSession alloc] initWithSessionID:@"Unicorn" displayName:nil sessionMode:GKSessionModePeer]; [session setDataReceiveHandler:self withContext:nil]; [session setDelegate:self]; [session setAvailable:YES]; NSLog(@"Session ID: %@", [session sessionID]); NSLog(@"Currently Available Peers: %i", [[session peersWithConnectionState:GKPeerStateAvailable] count]); if ([session isAvailable]) { NSLog(@"The Session Is Available"); } [connectToDeviceButton setTitle:@"Searching..." forState:UIControlStateNormal]; } else { NSLog(@"Currently Available Peers: %i", [[session peersWithConnectionState:GKPeerStateAvailable] count]); } </code></pre> <p>After the button is pressed the first time, everything appears to be working okay. And every time I press the button after that, it prints "Currently Available Peers: 0". This would be the expected output if I didn't have two devices sitting next to each other, running the program both with the button pushed. I also have all of the GKSessionDelegate methods implemented into this class, which all log a message to the console. None of those methods are ever run. All of this would indicate to me that the devices could not find each other.</p> <p>However, I have run the sample program GKRocket which uses GKSession to connect two devices and it works fine between these same two devices. I have compared the code of GKRocket to my program's code, and I have not found any differences that I think could effect GKSession.</p> <p>Any Suggestions?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload