Why is 'Simulate Background Fetch' leading to crash (libsystem_kernel.dylib`mach_msg_trap) since Xcode 8?

后端 未结 6 2193
深忆病人
深忆病人 2020-12-29 22:16

I\'m on macOS Sierra, Xcode 8, and get crashes whenever I try to Simulate Background Fetch on an actual iOS 10 device. This does NOT occur when using the simulator. This o

6条回答
  •  情深已故
    2020-12-29 23:05

    I just had this issue, it had something to do with pulling data from my backend and a casting type.

    If you aren't familiar with firebase just look at the last two lines of this. If you are, here is how I fixed it. My data coming in looked something like this

    "Node" : {
          "SubNode" : {
            "-KoB8OMIO0PLiTs8fUkJ" : {
          "ImageName" : "DSC05833-2.jpg",
          "price" : 100,
        },
        "-KoB8Rh9PtSMaMUlaD91" : {
          "ImageName" : "DSC05780-2.jpg",
          "price" : 0,
        },
    

    And my code to pull.

    ref.child("Node").child("SubNode").child(uniqueidID).observeSingleEvent(of: DataEventType.value, with: { (snapshot) in
            if snapshot.childrenCount > 0
            {
                let jsonPhoto = snapshot.value as? [String: AnyObject]
                let mageName = jsonPhoto?["ImageName"] as! String            
                photoObj.imagePrice = jsonPhoto?["price"] as! Double //error, Swift didn't catch, just froze my app
            }
    })
    

    it worked if value was 100 -> Double, and then for some reason firebase was failing when I casted 0 -> Double

    So I fixed how I casted it

    I originallyy had this:

    photoObj.imagePrice = jsonPhoto?["price"] as! Double // caused error
    

    to..

     photoObj.imagePrice = jsonPhoto?["price"] as? Double ?? 0.00 //fixed error
    

提交回复
热议问题