我在startMonitoringSignificantLocationChanges
iOS 8
问题
使用以下代码时,我的iOS 8物理设备和模拟器,从未点击didUpdateLocations
方法:
-(void)viewDidLoad {
if (self.locationManager==nil) { self.locationManager = [[CLLocationManager alloc] init]; }
self.locationManager.activityType = CLActivityTypeFitness;
self.locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
self.locationManager.delegate = self;
if ([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
NSLog(@“requestAlwaysAuthorization”);
[self.locationManager requestAlwaysAuthorization];
}
[self.locationManager startMonitoringSignificantLocationChanges];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
NSLog(“didUpdateLocation”);
}
如果我用startMonitoringSignificantLocationChanges
替换startUpdatingLocation
,物理设备会收到一个更新(这不是我期望的),但模拟器会继续接收不断更新(这是我所期待的,但是不是我想要的。)
任何关于如何解决这个问题的想法都将非常感激。我也希望使用requestWhenInUseAuthorization
代替requestAlwaysAuthorization
,但我在其他地方读到,如果我想使用startMonitoringSignificantLocationChanges
,我需要使用requestAlwaysAuthorization
。
答案 0 :(得分:2)
您必须在plist文件中为关键NSLocationAlwaysUsageDescription
定义描述字符串<key>NSLocationAlwaysUsageDescription</key>
<string>With this mode, you will never miss location updates!</string>