【发布时间】:2016-05-30 19:04:58
【问题描述】:
我对 startMonitoringSignificantLocationChanges 有疑问。如果我为我的 locationManager 调用此方法,则 locationManager:didUpdateLocations: 方法只调用一次。现在,如果我在模拟器中启动一个驱动器(如 here 所述 - 调试 -> 位置 -> 高速公路驱动器),它将不再被调用。 Apple 规定应该每 500m 甚至每 5 到 15 分钟调用一次。我等了又等,没有成功。
这是小代码,我也做了一个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]);
}
【问题讨论】:
标签: ios location cllocationmanager