我試圖實現我的LocationManager如下:無法設置屬性與定製的setter
開始更新使用者的位置
- (void)startStandardUpdates {
if (self.locationManager == nil) {
self.locationManager = [[CLLocationManager alloc] init];
}
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
// Set a movement threshold for new events
self.locationManager.distanceFilter = kCLLocationAccuracyNearestTenMeters;
[self.locationManager startUpdatingLocation];
CLLocation *currentLocation = self.locationManager.location;
if (currentLocation) {
self.currentLocation = currentLocation;
}
}
實現自定義的制定者MY PROPERTY發送通知
- (void)setCurrentLocation:(CLLocation *)currentLocation {
self.currentLocation = currentLocation;
NSLog(@"%f", currentLocation.coordinate.latitude);
//Notify the app of the location change
NSDictionary *userInfo = [NSDictionary dictionaryWithObject:self.currentLocation forKey:kIFLocationKey];
dispatch_async(dispatch_get_main_queue(), ^{
[[NSNotificationCenter defaultCenter] postNotificationName:kIFLocationChangeNotification object:nil userInfo:userInfo];
});
}
的問題是: 當我運行該應用程序,我在調試模式和叔得到一個「BAD_EXEC(代碼2)」中的錯誤「setCurrentLocation」方法的消息他的應用已掛斷。但我不明白這個問題。我錯過了什麼嗎?就我所見,在「startStandardUpdates」中,如果位置管理器找到用戶的位置,則使用我的自定義設置器「self.currentLocation = currentLocation」更新屬性「currentLocation」。
感謝您的幫助提前! 關於 塞巴斯蒂安