【发布时间】:2016-02-24 17:57:43
【问题描述】:
当应用程序处于活动状态并在前台运行时,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。已启用后台模式并已选择位置更新选项
【问题讨论】:
-
您的 CLLocationManager 是一个局部变量。大错。它应该是某种持久对象,例如一个实例变量/属性。
-
@matt 我已将 CLLocation 管理器声明为属性,但问题仍然存在
-
您发布的代码使用局部变量来保存位置管理器。如果这不是您的实际代码,请显示您的实际代码。
-
@DuncanC ,请查看编辑后的实际代码
-
得到了解决方案,我没有使用allowBackgroundLocationUpdates
标签: ios cllocationmanager