GKSession 的问题。无法识别可用设备
大家好,我正在使用以下代码来识别蓝牙上的可用设备。
_session = [[GKSession alloc]initWithSessionID:sessionid displayName:sessionid sessionMode:GKSessionModePeer];
_session.delegate = self;
[_session setDataReceiveHandler:self withContext:nil];
_session.available = YES;
我还添加了委托方法
- (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);
break;
}
case GKPeerStateAvailable:
{
NSLog(@"Available : %@",peerID);
break;
}
case GKPeerStateUnavailable:
{
NSLog(@"Un Available : %@",peerID);
break;
}
default:
break;
}
}
,但是这个方法永远不会被调用。可能是什么问题? 请帮我 !!!
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);
break;
}
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 !!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嗯,代码看起来不错。
你有正确声明的代表吗?我的意思是< GKSessionDelegate >在你的 .h 中?
您可以尝试在没有 displayName 的情况下初始化 GKSession:
well, code seems fine.
do you have delegate declared properly? I mean < GKSessionDelegate > in your .h ?
Could you try initializing GKSession without displayName:
确保他们使用相同的 sessionID。尝试使用 NULL 作为会话 ID,应用程序将为您创建一个。
Make sure they use the same sessionID. Try NULL as session ID instead and the app will make one for you.