StartMonitoringSignificantLocationChanges 是否在低功耗模式下工作

问题描述 投票:0回答:1

我想在我的应用程序中添加 StartmonitoringSignificantLocationChanges,但它可以在低功耗模式下工作吗?

Apple 的文档说后台活动将关闭,这是否适用于 StartmonitoringSignificantLocationChanges

swift core-location battery
1个回答
0
投票

是的,这可以在低功耗模式下工作。 TLDR:将

pausesLocationUpdatesAutomatically
设置为
false

更详细:

如果您在使用低精度和距离过滤时同时调用

startUpdatingLocation()
startMonitoringSignificantLocationChanges()
,应用程序可能会在后台暂停。特别是在启用低功耗模式时。然后您必须手动重新开始监控。

为了避免这种情况,有两种方法:

如果您只需要低精度位置,只需使用

startMonitoringSignificantLocationChanges()
并将
pausesLocationUpdatesAutomatically
设置为 false。

连续高精度背景定位:

  • 将 allowedBackgroundLocationUpdates 设置为 TRUE
  • 不要设置distanceFilter(或将其设置为kCLDistanceFilterNone)
  • 使用 kCLLocationAccuracyHundredMeters 或更好的所需准确度

或者,您可以通过将showsBackgroundLocationIndicator 设置为

true
来启用位置指示器。这个很奇怪,但它适用于 iOS 16.4 - 17.2。据我所知,这会导致某种程度的恢复到 iOS 16.x 之前的行为,其中监控没有暂停/根本没有暂停。

© www.soinside.com 2019 - 2024. All rights reserved.