2017-08-08 98 views
0

我有幾個客戶抱怨我的應用程序崩潰。我從來沒有能夠重現它。 Crashlitics已檢測到崩潰:解包時出現崩潰可選

func addDevice(unconfiguredDevice: UnconfiguredDevice) { 

    if let macSegment = unconfiguredDevice.macSegmentFromSSID { <<-CRASH 
     print("unconfigured mac: \(macSegment)") 

     if let setupDevice = self.unconfiguredDevices.value.first(where: { Device in Device.macEnd == unconfiguredDevice.macSegmentFromSSID! }) { 
      setupDevice.unconfiguredDevice = unconfiguredDevice 
     } else { 
      self.unconfiguredDevices.value.append(SetupDevice(unconfiguredDevice: unconfiguredDevice)) 
     } 
    } 
} 

崩潰類型是EXC_BREAKPOINT。我在這裏看到了其他幾個線程,這種類型的崩潰可能與可選的解包有關,並且確實macSegment方法在那裏返回一個可選項。但我不明白這個問題可能是什麼。 (順便提一下,這種方法用於檢測可通過WAC配置的設備)。

任何想法/提示/建議?

+0

'UnconfiguredDevice'是隱式解包的可選項嗎?如果是這樣,你應該用'?'標記它:'if let macSegment = unconfiguredDevice?.macSegmentFromSSID {' – the4kman

+0

'你試圖強制打開nil值。問題在這裏unconfiguredDevice.macSegmentFromSSID! – iMuzahid

+0

UnconfiguredDevice由WAC返回..我不認爲它是可選的.. macSegment是一個擴展方法,它返回一個可選的。 – user426132

回答

0

發生崩潰是因爲macSegmentFromSSID在你試圖拆包時爲零。 試試就像

if let setupDevice = self.unconfiguredDevices.value.first(where: { Device in Device.macEnd == macSegment}) { 
      setupDevice.unconfiguredDevice = unconfiguredDevice 
     } 
+0

這就是我的想法......但是對於崩潰的可重複性(0在我身邊)我需要發佈一個測試版本,看看測試版測試者說了些什麼。 – user426132

+0

@ user426132 hmm okk。 –

+0

@ user426132如果你這樣做: if unconfiguredDevice.macSegmentFromSSID!= nil {//其他代碼在這裏。 let macSegment = unconfiguredDevice.macSegmentFromSSID } –