【问题标题】:allowsBackgroundLocationUpdates only working for a few seconds允许BackgroundLocationUpdates 只工作几秒钟
【发布时间】: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


【解决方案1】:

您需要启用后台模式(位置),只要您的位置管理器能够接收位置更新,您的应用就会收到所有蓝牙数据。

正如@Paulw11 在 cmets 中提到的,使用重要的位置更新将大大减少电池使用量。

这是Apple guide的链接。

这是与在后台获取位置更新相关的question 的链接。

【讨论】:

    猜你喜欢
    • 2021-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多