Issue with the GKSession . Cant identify the available devices
Hi All I am using the following code to identify the available devices on bluetooth.
_session = [[GKSession alloc]initWithSessionID:sessionid displayName:sessionid sessionMode:GKSessionModePeer];
_session.delegate = self;
[_session setDataReceiveHandler:self withContext:nil];
_session.available = YES;
I have alos added the delegate method
- (void)session:(GKSession *)session peer:(NSString *)peerID didChangeState:(GKPeerConnectionState)state{
NSLog(@"state : %@",state);
switch (state)
{
case GKPeerStateConnected:
{
NSLog(@"%@ connected ",peerID);
break;
}
case GKPeerStateDisconnected:
{
NSLog(@"%@ disconnected ",peerID);
brea开发者_开发问答k;
}
case GKPeerStateAvailable:
{
NSLog(@"Available : %@",peerID);
break;
}
case GKPeerStateUnavailable:
{
NSLog(@"Un Available : %@",peerID);
break;
}
default:
break;
}
}
But this method is never being called . What can be the issue ? Please help me !!!
well, code seems fine. do you have delegate declared properly? I mean < GKSessionDelegate > in your .h ?
Could you try initializing GKSession without displayName:
_session = [[GKSession alloc]initWithSessionID:sessionid displayName:nil sessionMode:GKSessionModePeer];
Make sure they use the same sessionID. Try NULL as session ID instead and the app will make one for you.
精彩评论