2016-04-13 51 views
0

杉杉我調用一個方法從的LocationManager用於更新的位置(didUpdateLocations)。 在這個方法中,我使用了一個postNotification,一切正常。 但是,當我第二次調用locationManager的方法時,出現一個錯誤,「終止應用程序由於未捕獲的異常'NSInvalidArgumentException',原因:' - [NSMallocBlock sendMessageNotification:]:無法識別的選擇器發送到實例0x17026fac0'」爲什麼postNotification在Swift中的第二次調用中失敗?

[誤讀的信息變量]

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { 
    debugLog("locations \(locations)") 

    if let location = locations.last { 

     let mMessage = Message() 
     mMessage.latitude = location.coordinate.latitude 
     mMessage.longitude = location.coordinate.longitude 
     let userInfo = ["message": JSONSerializer.toJson(mMessage)] 

     if !userInfo.isEmpty { 
      NSNotificationCenter.defaultCenter().postNotificationName("__SEND_MESSAGE__", 
       object: nil, 
       userInfo: userInfo) 
     } 


    } 
+0

請出示您的代碼和堆棧跟蹤,但看起來你以某種方式引用釋放內存。 – Paulw11

+0

我添加的方法,但在堆棧跟蹤只能說終止應用程序由於未捕獲的異常「NSInvalidArgumentException」,原因是:「 - [NSMallocBlock sendMessageNotification:]:無法識別的選擇發送到實例0x17026fac0」 – shadow

+0

爲什麼你連載對象變成JSON?您可以將Message對象添加到字典中。事實上,你可以只添加我的JSON數據發送到服務器的位置或location.coordinate對象 – Paulw11

回答

0

在我的代碼是缺少刪除的觀察者,在同一個班,我添加了通知。

deinit { 
    // perform the deinitialization 
    NSNotificationCenter.defaultCenter().removeObserver(self) 
} 

謝謝。

相關問題