0
我有startMonitoringSignificantLocationChanges的问题。如果我将此方法称为我的locationManager,则方法只会被调用一次。现在,如果我在模拟器中启动Drive(如描述here - Debug - > Location - > Freeway Drive),则不会再调用它。苹果公司规定,应该每隔500米或甚至每5至15分钟调用一次。我等待,等待,并没有成功。startMonitoringSignificantLocationChanges代表只调用一次
这是小代码,我也做了Github minimal example。当然也不会调用错误方法。它没有在真正的汽车上进行测试,因为我认为它应该先在模拟器中运行。我在这里错过了什么?
- (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]);
}