我有一個已發佈的應用程序,它使用Multipeer conncectivity定期發送少量數據。我正在使用MCNearbyServiceAdvertiser和MCNearbyServiceBrowser。我測試時一切正常。不過,我一直收到來自我的用戶的崩潰報告,不是很多,但足以值得我的關注。在多對等連接中邀請對等體時偶爾發生崩潰
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** - [__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[2]'
Last Exception Backtrace:
0 CoreFoundation 0x30b8cf03 __exceptionPreprocess + 131
1 libobjc.A.dylib 0x3b321ce7 objc_exception_throw + 36
2 CoreFoundation 0x30acad3f -[__NSPlaceholderDictionary initWithObjects:forKeys:count:] + 532
3 CoreFoundation 0x30acab03 +[NSDictionary dictionaryWithObjects:forKeys:count:] + 48
4 MultipeerConnectivity 0x32420e87 -[MCNearbyServiceBrowser syncInvitePeer:toSession:withContext:timeout:] + 452
5 MultipeerConnectivity 0x324220cf __67-[MCNearbyServiceBrowser invitePeer:toSession:withContext:timeout:]_block_invoke + 84
6 libdispatch.dylib 0x3b80ad53 _dispatch_call_block_and_release + 8
7 libdispatch.dylib 0x3b80fcbd _dispatch_queue_drain + 486
8 libdispatch.dylib 0x3b80cc6f _dispatch_queue_invoke + 40
9 libdispatch.dylib 0x3b8105f1 _dispatch_root_queue_drain + 74
10 libdispatch.dylib 0x3b8108dd _dispatch_worker_thread2 + 54
11 libsystem_pthread.dylib 0x3b93bc17 _pthread_wqthread + 296
12 libsystem_pthread.dylib 0x3b93badc start_wqthread + 6
儘管做了很多努力,但我一直無法重新創建崩潰。我曾嘗試將應用程序置於後臺,斷開連接,打開和關閉網絡等。通常,重新連接很好,有時在點擊「重新連接按鈕」後,但沒有崩潰。有沒有人有關於這個原因的提示,或者至少如何強制這個o發生?
瀏覽器側看起來是這樣的:
-(void)setUpPP{
self.PPid = [[MCPeerID alloc] initWithDisplayName:@"PhotoFinish"];
self.SSid = [[MCPeerID alloc] init];
self.PPsession = [[MCSession alloc] initWithPeer:self.PPid securityIdentity:nil encryptionPreference:MCEncryptionNone];
self.PPsession.delegate = self;
self.PPbrowser = [[MCNearbyServiceBrowser alloc] initWithPeer:self.PPid serviceType:@"sprinttimer" ];
self.PPbrowser.delegate = self;
[self.PPbrowser startBrowsingForPeers];
}
-(IBAction)startSync:(id)sender {
[self.PPbrowser invitePeer:self.SSid toSession:self.PPsession withContext:nil timeout:10];
}
-(void)session:(MCSession *)session peer:(MCPeerID *)peerID didChangeState:(MCSessionState)state{
NSString *displayString;
if (state == MCSessionStateConnected && self.PPsession) {
[email protected]"Start Sender connected";
} else if (state == MCSessionStateNotConnected && self.PPsession) {
[email protected]"No Start Sender in range";
connected=NO;
}
[self performSelectorOnMainThread:@selector(displaySync:) withObject:displayString waitUntilDone:NO];
}
-(void)browser:(MCNearbyServiceBrowser *)browser foundPeer:(MCPeerID *)peerID withDiscoveryInfo:(NSDictionary *)info{
self.SSid=peerID;
}
感謝您的意見。你是對的,在獲取值之前分配SSid並不理想。我會改變這一點。但是,似乎問題(至少部分)是設備連接到自身。因此,檢查並確保在丟失連接時拆除會話似乎改善了事情。真的很沮喪,不能重新創建崩潰,但我不得不猜測,發佈更新並查看哪些崩潰報告正在進入。 – Sten