startMonitoringSignificantLocationChanges 委托只调用一次
startMonitoringSignificantLocationChanges Delegate only called once
我对 startMonitoringSignificantLocationChanges 有疑问。如果我为我的 locationManager 调用此方法,则 locationManager:didUpdateLocations:
方法只被调用一次。现在,如果我在模拟器中启动一个驱动器(如 here - 调试 -> 位置 -> 高速公路驱动器所述),它不再被调用。 Apple 规定它应该每 500 米甚至每 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]);
}
好的,我刚刚从 Github 下载了我自己的最小项目,并使用 iPhone 5S 模拟器进行了尝试。它在那里工作。之前我只用 6S 试过,但没有用。现在将在设备 6(S) 上试用,希望也能在那里工作..
但也许在不久的将来会对某人有所帮助:)
我对 startMonitoringSignificantLocationChanges 有疑问。如果我为我的 locationManager 调用此方法,则 locationManager:didUpdateLocations:
方法只被调用一次。现在,如果我在模拟器中启动一个驱动器(如 here - 调试 -> 位置 -> 高速公路驱动器所述),它不再被调用。 Apple 规定它应该每 500 米甚至每 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]);
}
好的,我刚刚从 Github 下载了我自己的最小项目,并使用 iPhone 5S 模拟器进行了尝试。它在那里工作。之前我只用 6S 试过,但没有用。现在将在设备 6(S) 上试用,希望也能在那里工作..
但也许在不久的将来会对某人有所帮助:)