У меня проблема с startMonitoringSignificantLocationChanges. Если я вызываю этот метод для моего locationManager, метод locationManager:didUpdateLocations:
вызывается ровно один раз. Теперь, если я запустил Drive in Simulator (как описано here - Debug -> Location -> Freeway Drive), он больше не вызывается. Apple заявляет, что ее следует называть каждые 500 или даже каждые 5-15 минут. И я ждал, ждал и ждал без успеха.startMonitoringSignificantLocationChanges Делегат вызывает только один раз
Вот небольшой код, и я сделал также Github minimal example. Конечно, метод ошибок также никогда не называется. Он не тестируется на реальном устройстве в автомобиле, потому что я думал, что он должен сначала работать в Simulator. Что мне здесь не хватает?
- (void)viewDidLoad {
[super viewDidLoad];
if(self.locationManager == nil){
self.locationManager = [[CLLocationManager alloc] init];
}
// Set the delegate
self.locationManager.delegate = self;
[self.locationManager requestAlwaysAuthorization];
[self.locationManager startMonitoringSignificantLocationChanges];
}
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations{
CLLocation *currentLoc = [locations lastObject];
NSLog(@"New Location: %f/%f, Locations: %lu", currentLoc.coordinate.latitude, currentLoc.coordinate.longitude,(unsigned long)[locations count]);
}
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{
NSLog(@"Loc Error: %@", [error userInfo]);
}