首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >确定GKSession蓝牙设备何时超出范围

确定GKSession蓝牙设备何时超出范围
EN

Stack Overflow用户
提问于 2013-02-12 06:39:36
回答 1查看 293关注 0票数 0

我正在使用GKSession, GKSessionDelegate实现多个iX (iPod、iPad、iPhone、.)之间的点对点蓝牙连接。设备。我想显示范围内当前可用/连接设备的列表。

我现在依靠的是

- (void)session:(GKSession *)session peer:(NSString *)peerID didChangeState:(GKPeerConnectionState)state

做这件事。不幸的是,当设备超出范围时,似乎无法可靠地调用此方法。是否有“更好”的方法来确定一个设备是否在范围内?

一些代码:

代码语言:javascript
复制
- (void)session:(GKSession *)session peer:(NSString *)peerID didChangeState:(GKPeerConnectionState)state {

    NSString* connectionStateString=
    (state==GKPeerStateAvailable)?@"available":
    (state==GKPeerStateUnavailable)?@"unavailable":
    (state==GKPeerStateConnected)?@"connected":
    (state==GKPeerStateDisconnected)?@"disconnected":@"connecting";
    // Add the peer to the Dictionary
    NSArray* details=[NSArray arrayWithObjects:[session displayNameForPeer:peerID],connectionStateString,nil];
    [connectionPeers setObject:details forKey:peerID];

    if (state == GKPeerStateAvailable) {
        NSLog(@"Adding peerID:%@",peerID);
        [session connectToPeer:peerID withTimeout:60];//'connect' to everything, so data can be sent
    }
    else if (state == GKPeerStateUnavailable || state==GKPeerStateDisconnected) {
        [connectionPeers removeObjectForKey:peerID];
    }
    [self listPlayers];
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-03-13 20:34:29

GKSession是建立在蓝牙的Bonjour之上的,我相信您的问题是,bonjour服务仍然显示为活动的,因为Bonjour不会在对等端断开网络时使服务广告失效。我认为,mDNS记录只在mDNS缓存超时发生时(不能进行调整)或广告对等点手动使服务无效时过期。

我不认为GKSession会轻易地通过广告来做你想做的事。但是,一旦连接的节点超出了蓝牙范围,它们就应该断开连接。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14826882

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档