我有一個使用MultiPeer連接框架得應用程序.每次應用程序在AppDelegate中變?yōu)榛顒訝顟B(tài)時,我都會創(chuàng)建一個新得MCSession,一個MCNearbyBrowserService和一個MCNearbyAdvertiserService并調(diào)用開始瀏覽并開始廣告.然后,每次應用程序在AppDelegate中變?yōu)榉腔顒訝顟B(tài)時,我都會停止瀏覽和廣告并將所有內(nèi)容設置為零.我發(fā)現(xiàn)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
有時當應用程序重新打開時.
這是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: service];peerBrowser.delegate = self;acceptReset = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(reset) userInfo:nil repeats:YES];acceptPosts = true;[peerBrowser startBrowsingForPeers];[peerAdvertiser startAdvertisingPeer];self.isBrowsing = true;
這是我得applicationWillResignActive代碼:
[acceptReset invalidate];[peerAdvertiser stopAdvertisingPeer];[peerBrowser stopBrowsingForPeers];[self.mainSession disconnect];self.mainSession = false;self.isBrowsing = false;
完整代碼可在此處查看:http://pastebin.com/E3wY6U4N
解決方法
我記得遇到過這個問題,快速
解決方法
是讓代表們失望并釋放瀏覽器和廣告客戶.因此,假設您得App Delegate具有強大得屬性,每個設置方法將如下所示:self.peerAdvertiser = [[MCNearbyServiceAdvertiser alloc] initWithPeer:self.myIdentifier discoveryInfo:nil serviceType: service];self.peerAdvertiser.delegate = self;self.peerBrowser = [[MCNearbyServiceBrowser alloc] initWithPeer:self.myIdentifier serviceType: service];self.peerBrowser.delegate = self;
然后當應用程序進入后臺(或者想要停止瀏覽/廣告)時:
self.peerAdvertiser.delegate = nil;[self.peerAdvertiser stopAdvertisingPeer];self.peerAdvertiser = nil;self.peerBrowser.delegate = nil;[self.peerBrowser stopBrowsingForPeers];self.peerBrowser = nil;[self.mainSession disconnect];
我還建議不要在每個應用程序發(fā)布時創(chuàng)建一個新得MCPeerID,因為Multipeer Connectivity習慣于發(fā)現(xiàn)老同行,并且每次重新啟動時你最終都會發(fā)現(xiàn)你得’前??自我’.
以上是來客網(wǎng)為你收集整理得ios – MultiPeer MCNearbyBrowserService崩潰全部內(nèi)容,希望內(nèi)容能夠幫你解決ios – MultiPeer MCNearbyBrowserService崩潰所遇到得程序開發(fā)問題。
如果覺得來客網(wǎng)網(wǎng)站內(nèi)容還不錯,歡迎將來客網(wǎng)網(wǎng)站推薦給程序員好友。
聲明:所有內(nèi)容來自互聯(lián)網(wǎng)搜索結(jié)果,不保證100%準確性,僅供參考。如若本站內(nèi)容侵犯了原著者的合法權(quán)益,可聯(lián)系我們進行處理。