我正在创建一个通过 Multipeer Connectivity Framework 使用远程控制功能的 iOS/macOS 应用程序。由于要远程监控的设备会运行很长时间,因此使用自动视图控制器方法是不可行的,因为监控设备可能会被锁定或进入睡眠状态然后断开连接。所以我使用了程序化方法,这样当监控设备失去连接时,它们会在解锁/唤醒时自动配对,并再次启动应用程序。我的连接使用 ViewController 方法可以正常工作,但不能使用编程委托方法。广告、浏览和邀请工作正常,但是当远程接受邀请时,我收到几个错误,然后连接失败。什么'
那么它为什么要尝试使用 GameCenter 框架呢?为什么接受邀请后失败了?会不会只是 Xcode 8 / Swift 3 /iOS 10 / macOS Sierra Beta SDK 中的错误?
[ViceroyTrace] [ICE][ERROR] ICEStopConnectivityCheck() found no ICE check with call id (2008493930)
[GCKSession] Wrong connection data. Participant ID from remote connection data = 6FBBAE66, local participant ID = 3A4C626C
[MCSession] GCKSessionEstablishConnection failed (FFFFFFFF801A0020)
Peer Changing
Failed
[GCKSession] Not in connected state, so giving up for participant [77B72F6A] on channel [0]
这是我的连接类的代码
func startAdvertisingWithoutUI () {
if advertiserService == nil {
advertiserService = MCNearbyServiceAdvertiser (peer: LMConnectivity.peerID, discoveryInfo: nil, serviceType: "mlm-timers")
advertiserService?.delegate = self
session.delegate = self
}
advertiserService?.startAdvertisingPeer()
}
func browserForNearbyDevices () {
if browserService == nil {
browserService = MCNearbyServiceBrowser (peer: LMConnectivity.peerID, serviceType: "mlm-timers")
browserService?.delegate = self
session.delegate = self
}
browserService?.startBrowsingForPeers()
}
func sendInvitation(to peer: MCPeerID) {
browserService?.invitePeer(peer, to: session, withContext: nil, timeout: 60)
}
func advertiser(_ advertiser: MCNearbyServiceAdvertiser, didReceiveInvitationFromPeer peerID: MCPeerID, withContext context: Data?, invitationHandler: (Bool, MCSession?) -> Void) {
let trustedNames = GetPreferences.trustedRemoteDevices
for name in trustedNames {
if name == peerID.displayName {
invitationHandler(true,session)
return
}
}
invitationHandler (false, session)
}