2

I have been working to try getting Multipeer Connectivity working in our app in a relatively short period of time. Most things have gone fairly smooth but we have hit a really puzzling issue now.

We have all the data being transferred fine when following the happy path but then when trying to implement the error handling... Which is done through turning off the wifi mid transfer.. My code...:

Sharer:

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)")
                    }
                })

            }
        }
    }

Receiver:

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

The errors we receive:

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).

These lines print out more based on the amount of progress left.

Then we also get the following stack in xcode (I can't add images directly into my posts yet :< )

Stack Frame from the thread causing the error

JoellyR
  • 153
  • 1
  • 17
  • 1
    Can you share the stack frames from that trace? What code was being run by that thread when it crashed? – Dave Weston Mar 07 '17 at 19:36
  • okay will do asap – JoellyR Mar 07 '17 at 21:13
  • what do you mean by stack frames? do you want me to send u a screen shot of the debugger session? or is there a better way to send it? @DaveWeston – JoellyR Mar 08 '17 at 03:33
  • In the panel on the left-hand side of Xcode, one of them will show the stack frames that ended in that crash. It will list all of the methods that were executed leading when the crash happened, with the most recent at the top. Then we'll want to see the code you wrote that triggered the crash. The image you shared has the machine code where the crash actually happened, but that doesn't tell us how we got there. – Dave Weston Mar 08 '17 at 03:45
  • @DaveWeston Hey i attached the stack frame of the thread causing the crash.. is that good enough or do you need all the threads? – JoellyR Mar 08 '17 at 18:31
  • @DaveWeston Hey dave i appreciate you help but it seems like this bug is linked to a bug in apples framework due to the localURL in the didFinishRecieving function not being an optional, but the value on error or progress cancelled is nil. I will post an answer later with a link to a SO post explainingthe issue. – JoellyR Mar 08 '17 at 22:09

1 Answers1

1

It seems like this bug is linked to a bug in apples framework due to the localURL in the didFinishReceivingResourceWithName function not being an optional.The value on error or progress cancelled is nil. I have come to this conclusion after looking through each call in the crashing thread then finding a related SO Post

Community
  • 1
  • 1
JoellyR
  • 153
  • 1
  • 17