我有一个使用MultiPeer连接框架的应用程序.每次应用程序在AppDelegate中变为活动状态时,我都会创建一个新的MCSession,一个MCNearbyBrowserService和一个MCNearbyAdvertiserService并调用开始浏览并开始广告.然后,每次应用程序在AppDelegate中变为非活动状态时,我都会停止浏览和广告并将所有内容设置为零.我发现MCNearbyBrowserService导致其syncQueue崩溃:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** - [__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[2]'
*** First throw call stack:
(0x2de3ee8b 0x381396c7 0x2dd7caef 0x2dd7c8b3 0x2f648167 0x2f6493af 0x3861e103 0x38622e77 0x3861ff9b 0x38623751 0x386239d1 0x3874ddff 0x3874dcc4)
libc++abi.dylib: terminating with uncaught exception of type NSException
Run Code Online (Sandbox Code Playgroud)
有时当应用程序重新打开时.
这是applicationDidBecomeActive的代码:
self.myIdentifier = [[MCPeerID alloc] initWithDisplayName:[self.class createHash:20]];
self.mainSession = [[MCSession alloc] initWithPeer:self.myIdentifier];
self.mainSession.delegate = self;
peerAdvertiser = [[MCNearbyServiceAdvertiser alloc] initWithPeer:self.myIdentifier discoveryInfo:nil serviceType: service];
peerAdvertiser.delegate = self;
peerBrowser = [[MCNearbyServiceBrowser alloc] initWithPeer:self.myIdentifier serviceType: …Run Code Online (Sandbox Code Playgroud)