应用程序在后台时未调用 didUpdateLocations
didUpdateLocations not being called when app is in background
didUpdateLocations 在应用程序处于活动状态且 运行 在前台时工作正常,但一旦应用程序进入后台就停止工作
在.h文件中
@property (nonatomic, strong) CLLocationManager *customerLocationManager;
在 .m 文件中
@synthesize customerLocationManager;
customerLocationManager = [[CLLocationManager alloc] init];
customerLocationManager.delegate = self;
customerLocationManager.desiredAccuracy = kCLLocationAccuracyBest;
customerLocationManager.distanceFilter = kCLDistanceFilterNone;
if(IS_OS_8_OR_LATER) {
[customerLocationManager requestAlwaysAuthorization];
}
[customerLocationManager startUpdatingLocation];
我已经在 info.plist 中集成了 NSLocationAlwaysUsageDescription。后台模式已启用,并且已选择 位置更新 选项
I have integrated NSLocationAlwaysUsageDescription in info.plist. Background modes have been enabled and Location Updates option has been selected
很好,但是在 iOS9 中还有一个要求:您必须将位置管理器的 allowsBackgroundLocationUpdates
设置为 YES。你没有这样做,所以你不会获得后台位置更新。
didUpdateLocations 在应用程序处于活动状态且 运行 在前台时工作正常,但一旦应用程序进入后台就停止工作
在.h文件中
@property (nonatomic, strong) CLLocationManager *customerLocationManager;
在 .m 文件中
@synthesize customerLocationManager;
customerLocationManager = [[CLLocationManager alloc] init];
customerLocationManager.delegate = self;
customerLocationManager.desiredAccuracy = kCLLocationAccuracyBest;
customerLocationManager.distanceFilter = kCLDistanceFilterNone;
if(IS_OS_8_OR_LATER) {
[customerLocationManager requestAlwaysAuthorization];
}
[customerLocationManager startUpdatingLocation];
我已经在 info.plist 中集成了 NSLocationAlwaysUsageDescription。后台模式已启用,并且已选择 位置更新 选项
I have integrated NSLocationAlwaysUsageDescription in info.plist. Background modes have been enabled and Location Updates option has been selected
很好,但是在 iOS9 中还有一个要求:您必须将位置管理器的 allowsBackgroundLocationUpdates
设置为 YES。你没有这样做,所以你不会获得后台位置更新。