我从locationManager调用一个方法来更新位置(didUpdateLocations)。 在这个方法中我使用postNotification,一切都好。 但是当我第二次调用来自locationManager的方法时,出现了一个错误,“由于未捕获的异常终止应用程序'NSInvalidArgumentException',原因:' - [ NSMallocBlock sendMessageNotification:]:无法识别的选择器发送到实例0x17026fac0' “
[错误信息变量]
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 :(得分:0)
在我的代码中缺少一个删除观察者,在我添加通知的同一个类中。
deinit {
// perform the deinitialization
NSNotificationCenter.defaultCenter().removeObserver(self)
}
感谢。