开发者

Issue with the GKSession . Cant identify the available devices

开发者 https://www.devze.com 2023-03-23 01:25 出处:网络
Hi All I am using the following code to identify the available devices on bluetooth. _session = [[GKSession alloc]initWithSessionID:sessionid displayName:sessionid sessionMode:GKSessionModePeer];

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号