0

GKSession is searching itself(the same device), why? Even in GKRocket Example, why does so?

How can I stop not to make self connection?

Chatar Veer Suthar
  • 15,541
  • 26
  • 90
  • 154

3 Answers3

1

make sure only one session is open from the device.. the GKSession looks for sessions with matching id... if you create a new session from your device with the same id, it is going to find the older session..

Swapnil Luktuke
  • 10,385
  • 2
  • 35
  • 58
  • ,, I still didn't get what exactly you means, can U explain more ? – Chatar Veer Suthar May 10 '11 at 10:51
  • I think this means that if your app recreates the session for some reason using the same sessionID then two such sessions exist. One of the sessions then thinks the other is another device and lists it on the table of peers. Is this right? – Tim Sep 17 '13 at 15:06
0

I got this problem in a modified version of GKRocket. When a peer disconnected the app returned to the front screen and then reloaded the view that initiated the session.

You need to fix this by instantiating the class that creates your GKSession as early in the App as possible. The user must not navigate any further back at any time until they close the app. Then maintain a pointer to the session controller class throughout your navigation stack so that you can call for peer lists etc.

These methods are from the first view controller after AppDelegate

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

//We setup the GKSession at this stage so that we do not create duplicate sessions as
//the user navigates to and from the game lobby controller finding and managing peers
manager = [[SessionManager alloc] init];
manager.lobbyDelegate = nil;  //There is no game lobby at this stage so we nil this.
[manager setupSession];
// call the session manager's setup method to create the session. It will start
//looking for peers right away, but we won't see that until we go to the game lobby

}

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
//Pass a pointer to the session manager along the line of segues
[[segue destinationViewController] setManager:self.manager];
}

This code is modified from GKRocket - check out that tutorial to see what methods like setupSession do.

Tim
  • 1,108
  • 13
  • 25
0

What you have to do is use:

session.available = NO;

on the device that is searching. Just set it to YES when the searching is over.

If the session is part of the AppDelegate:

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
Nate Symer
  • 2,185
  • 1
  • 20
  • 27