【发布时间】:2017-07-17 13:13:55
【问题描述】:
我有一个以 EXC_BREAKPOINT 结尾的可重复崩溃,如下图所示:
重现崩溃的步骤:
- 连接两台设备
- 使用 func sendResource(at resourceURL: URL, withName 资源名称:字符串, toPeer peerID: MCPeerID, withCompletionHandler completionHandler: ((Error?) -> Void)? = nil) -> 进度?
- 通过调用func disconnect()断开发起传输的设备
编辑:另一种重现崩溃的方法,通过调用 Progress.cancel() 步骤:
- 连接两台设备
- 开始传输并存储 Progress 对象 let progress: Progress = session.sendResource(...)
- 对进度对象调用取消,导致另一台设备崩溃progress.cancel()
我在 didFinishReceivingResourceWithName 行的代码:
func session(_ session: MCSession, didFinishReceivingResourceWithName resourceName: String, fromPeer peerID: MCPeerID, at localURL: URL, withError error: Error?) {
// transfer to local URL
MusicDownloadRequestor.sharedInstance.finishReceivingSongUploadAtLocalURL(tempUrl: localURL)
}
看起来我的代码没有在堆栈跟踪中调用...
* thread #25: tid = 0x806ec, 0x0000000100944af4 libswiftFoundation.dylib`static Foundation.DateComponents._unconditionallyBridgeFromObjectiveC (Swift.Optional<__ObjC.NSDateComponents>) -> Foundation.DateComponents with unmangled suffix "_merged" + 96, queue = 'com.apple.MCSession.callbackQueue', stop reason = EXC_BREAKPOINT (code=1, subcode=0x100944af4)
frame #0: 0x0000000100944af4 libswiftFoundation.dylib`static Foundation.DateComponents._unconditionallyBridgeFromObjectiveC (Swift.Optional<__ObjC.NSDateComponents>) -> Foundation.DateComponents with unmangled suffix "_merged" + 96
frame #1: 0x0000000100114c60 MyAppSwift`@objc NetworkManager.session(MCSession, didFinishReceivingResourceWithName : String, fromPeer : MCPeerID, at : URL, withError : Error?) -> () + 168 at NetworkManager.swift:0
frame #2: 0x00000001a1dda028 MultipeerConnectivity`__79-[MCSession syncCloseIncomingStream:forPeer:state:error:reason:removeObserver:]_block_invoke + 208
frame #3: 0x0000000100c05258 libdispatch.dylib`_dispatch_call_block_and_release + 24
frame #4: 0x0000000100c05218 libdispatch.dylib`_dispatch_client_callout + 16
frame #5: 0x0000000100c12aec libdispatch.dylib`_dispatch_queue_serial_drain + 1136
frame #6: 0x0000000100c08ce0 libdispatch.dylib`_dispatch_queue_invoke + 672
frame #7: 0x0000000100c14e2c libdispatch.dylib`_dispatch_root_queue_drain + 584
frame #8: 0x0000000100c14b78 libdispatch.dylib`_dispatch_worker_thread3 + 140
frame #9: 0x000000018c2a32a0 libsystem_pthread.dylib`_pthread_wqthread + 1288
frame #10: 0x000000018c2a2d8c libsystem_pthread.dylib`start_wqthread + 4
更新 #1:将堆栈跟踪添加为文本
更新 #2:找到可能导致崩溃的原因,here's another crash with unconditionallyBridgeFromObjectiveC
我认为问题在于 URL 被作为 nil 传递给 didFinishReceivingResourceWithName 但参数是非可选的。这是有道理的,因为如果文件传输失败,URL 将不会有最终的归宿。有什么办法可以解决这个问题或拦截错误?
我认为这是一个 Apple 错误。有没有人有解决方法的建议?
【问题讨论】:
-
请将堆栈跟踪添加为文本。
-
@AminNegm-Awad 已更新,谢谢!
标签: ios swift multipeer-connectivity