2017-03-07 75 views
2

我一直在努力嘗試讓Multipeer Connectivity在相對較短的時間內在我們的應用程序中工作。大部分事情都很順利,但現在我們遇到了一個非常令人困惑的問題。Multipeer Connectivity IOS:didFinishReceivingResourceWithName錯誤處理(崩潰)

試圖執行錯誤處理......這是通過關閉wifi的中間傳送..我的代碼完成後跟隨快樂路徑但後來當我們正在傳輸的所有數據精...:

共享器:

func sendResource(data: Data?, name: String, fileName: String, peerId: MCPeerID){ 
     if data != nil{ 
      let url = createTransferFile(jsonData: data!, name: fileName) 

      if url != nil{ 
       session.sendResource(at: url!, withName: name, toPeer: peerId, withCompletionHandler: { (error) -> Void in 
        if error != nil{ 
         NSLog("Error in sending resource send resource: \(error!.localizedDescription)") 
        } 
       }) 

      } 
     } 
    } 

接收機:

func session(_ session: MCSession, didFinishReceivingResourceWithName resourceName: String, fromPeer peerID: MCPeerID, at localURL: URL, withError error: Error?) { 
     NSLog("%@", "didFinishReceivingResourceWithName: \(resourceName)") 
     if error != nil{ 
      NSLog("error in receiving") 
     } 
     if resourceName.contains("clinicDetails"){ 
      if error == nil{ 
       if let data = self.readClinicJsonFromFile(path: localURL){ 
        NSLog("passing to broadcast delegate") 
        sendDelegate?.addClinicDetails(self, clinicDetailsJSON: data) 

       }else{ 
        NSLog("there was an error in finding the retrieved file in clinic retrieve finished") 
        _ = Util.showAlert(retrievePatientDelegate as! UIViewController, code: 3021, actions: nil, isCustom: true) as! AlertController 
       } 
      }else{ 
       _ = Util.showAlert(retrievePatientDelegate as! UIViewController, code: 3021, actions: nil, isCustom: true) as! AlertController 
      } 
     }else if resourceName.contains("patients"){ 
      //NSLog("clinicId in retrievePatient: \(json["clinicId"])") 
      if error == nil{ 
       if let data = self.readPatientJsonFromFile(path: localURL){ 
        NSLog("passing to retrieve patients delegate") 
        retrievePatientDelegate?.addPatients(self, patientJSON: data , clinicId: resourceName.components(separatedBy: "/")[1]) 
       }else{ 
        NSLog("there was an error in finding the retrieved file in patient retrieve finished") 
        _ = Util.showAlert(retrievePatientDelegate as! UIViewController, code: 3021, actions: nil, isCustom: true) as! AlertController 

       } 
      }else{ 
       _ = Util.showAlert(retrievePatientDelegate as! UIViewController, code: 3021, actions: nil, isCustom: true) as! AlertController 
      } 
     }else if resourceName == "clinicList"{ 
      if error == nil{ 
       if let data = self.readClinicListJsonFromFile(path: localURL){ 
        NSLog("passing to retrieve retrieveDelegate") 
        retrieveDelegate?.addClinics(self, clinicsJSON: data["jsonData"] as! [[String:Any]], passcode: data["passcode"] as! String) 
       }else{ 
        NSLog("there was an error in finding the retrieved file in patient retrieve finished") 
        _ = Util.showAlert(retrievePatientDelegate as! UIViewController, code: 3021, actions: nil, isCustom: true) as! AlertController 
       } 
      }else{ 
       _ = Util.showAlert(retrievePatientDelegate as! UIViewController, code: 3021, actions: nil, isCustom: true) as! AlertController 
      } 
     } 
    } 

的錯誤,我們得到:

2017-03-06 16:52:54.416352 DC[2445:1444277] [GCKSession] Failed to send a DTLS packet with 78 bytes; sendmsg error: Can't assign requested address (49). 
2017-03-06 16:52:54.416560 DC[2445:1444277] [GCKSession] SSLWrite failed, packet was not sent for participant [05280B9E] channelID [4] DTLS context [0x103043ea0] pCList [0x10e94f960]; osStatus = -9803: errno = Can't assign requested address (49). 

這些行根據剩餘的進度打印出更多。

Then we also get the following stack in xcode(我不能添加圖像直接到我的職位,但:​​<)

Stack Frame from the thread causing the error

+1

您可以共享該跟蹤中的堆棧幀嗎?該線程在崩潰時正在運行哪些代碼? –

+0

好吧會盡快做 – JoellyR

+0

你是什麼意思的堆棧幀?你想讓我發送一個調試器會話的屏幕截圖嗎?還是有更好的方式發送它? @DaveWeston – JoellyR

回答

1

看起來這個錯誤被鏈接到一個bug在蘋果框架由於localURL在didFinishReceivingResourceWithName功能不是可選項。取消錯誤或進度的值爲零。我在通過崩潰線程中的每個調用查找後得出這個結論,然後找到相關的SO Post