I have a published app that uses Multipeer conncectivity to send small amounts of data at regular intervals. I am using MCNearbyServiceAdvertiser and MCNearbyServiceBrowser. Everything works fine when I test. However, I have been receiving crash reports from my users, not a lot, but enough to deserve my attention.
*** 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
Despite a lot of efforts I have been unable to recreate the crash. I have tried putting the app in the background, loosing connection, turning the network on and off etc. Usually everthing reconnects nicely, sometimes after tapping a "reconnect button", but no crashes. Does anyone have a tip about the cause or at least how to force this o happen?
The browser side looks like this:
-(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) {
displayString=@"Start Sender connected";
} else if (state == MCSessionStateNotConnected && self.PPsession) {
displayString=@"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;
}
It would be helpful to know what action triggers startSync:
but in setUpPP
you are assigning a meaningless instance of MCPeerID
(with no displayName
) to self.SSid
so I could see that crash happening if startSync:
is ever called before self.SSid
gets a real MCPeerID
assigned to it.
My suggestion would be to start out with self.SSid
as nil, and make sure that you are not sending invitations unless that property has a value. Going further I wouldn't rely on a single property to store an MCPeerID
that could have it's value changed before startSync:
is called.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.