【发布时间】:2016-12-16 18:42:44
【问题描述】:
我有一个蓝牙设备,当按下按钮时,它会在我的应用中触发定位服务。并且定位服务确实运行,但只运行了大约 8 秒。我在 didUpdateToLocation 委托方法中有一个 NSLog 输出 Location Found。它仅输出 8 秒的 NSLog。
当我将应用程序置于前台时,位置服务再次继续。这是我初始化位置管理器的方法:
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
[self.locationManager requestAlwaysAuthorization];
[self.locationManager requestWhenInUseAuthorization];
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[self.locationManager setAllowsBackgroundLocationUpdates:YES];
[self.locationManager allowsBackgroundLocationUpdates];
当按钮被按下时,我运行这个:
[self.locationManager startUpdatingLocation];
【问题讨论】:
-
为了在后台持续更新位置,您必须在应用处于前台时开始重大的位置变化监控
-
刚刚对其进行了测试并且它有效,但是没有办法对我的应用程序做我需要做的事情?有吗?
-
好吧,您只需要保留重要的位置更新。与完整的 GPS 位置更新相比,它具有较低的能量影响
标签: ios objective-c core-location