gpt4 book ai didi

ios - 在多点连接中邀请对等点时偶尔发生崩溃

转载 作者:行者123 更新时间:2023-11-29 12:47:18 28 4
gpt4 key购买 nike

我有一个已发布的应用程序,它使用 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

尽管我付出了很多努力,但我无法重现崩溃。我试过将应用程序置于后台、断开连接、打开和关闭网络等。通常一切都很好地重新连接,有时在点击“重新连接按钮”之后,但没有崩溃。有没有人知道原因或至少如何强制发生这种情况?

浏览器端是这样的:

-(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;
}

最佳答案

了解什么操作会触发 startSync: 会很有帮助,但在 setUpPP 中,您正在分配一个无意义的 MCPeerID 实例(没有 displayName) 到 self.SSid 所以我可以看到如果 startSync:self.SSid 之前被调用就会发生崩溃获取分配给它的真实 MCPeerID

我的建议是将 self.SSid 设置为 nil,并确保您不会发送邀请,除非该属性具有值。更进一步,我不会依赖单个属性来存储可以在调用 startSync: 之前更改其值的 MCPeerID

关于ios - 在多点连接中邀请对等点时偶尔发生崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23338748/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com