bla*_*bus 5 cocoa objective-c ios multipeer-connectivity
I have an app that's using the iOS 7 Multipeer Connectivity framework to advertise itself as well as browse for other devices. Why does my MCNearbyServiceBrowser instance find itself (the device the app is running on) and call the browser:foundPeer... delegate method? If I log the actual PeerID that I create to start advertising my device, as well as the discovered PeerID in the delegate method, they have different unique IDs but the same display name. Any ideas why?
不幸的是,这种情况很常见,这是由于底层的 bonjour 发现服务机制造成的。这实际上取决于一系列因素,包括重新广播 bonjour 可用性的某些网络设备。
在您的应用程序中避免这种情况的最佳方法是为您的 MCPeerID 使用唯一的字符串(我通常使用新的 UUID 字符串),并在对等浏览器 UI 中显示每个对等 ID 之前,根据您的本地名称检查每个对等 ID 的显示名称。
很快它就会看起来像这样
让 uuid = NSUUID().UUIDString
self.peer = MCPeerID(显示名称: uuid)
...
...当您从会话委托收到找到的对等消息时:
if peerID.displayName != self.peer.displayName { ... 将对等点添加到此处的可用对等点数组 }
| 归档时间: |
|
| 查看次数: |
390 次 |
| 最近记录: |