IOS 在应用程序终止而不使用 significantChange 时获取位置更新

标签 ios background cllocation terminate

对于该主题的冗余,我深表歉意,但尽管给出了所有答案,但我无法确定应用程序终止时获取 accuracyBest 位置更新的可能性。 我不想使用 monitoringSignificantChange,我想要最好的准确性;我不会在 AppStore 上提交应用程序,因此 Apple 限制也不是问题。

我经历过这些:

- Location update even when app is killed/terminated

- iOS update location even when app is terminated

- Working with location updates when app is terminated

- http://mobileoop.com/getting-location-updates-for-ios-7-and-8-when-the-app-is-killedterminatedsuspended

还有更多,但尚不清楚是否可能。我目前有我的项目,一切都适用于 significantChange,但我现在需要更高的准确性。

有人可以直接告诉我是否可以在应用程序被杀死时获得最准确的位置更新吗?

无限感谢,

最佳答案

查看 Apple 文档中的以下内容,您显然有 2 个替代方案可以避免使用重大位置更改从后台唤醒应用程序。 我已经用粗体标记了您可以用来重新启动应用程序(如果应用程序已终止)的服务。

Using Location Services in the Background Most location services are meant to be used while your app is in the foreground but some can also run in the background. In some cases, location events can even cause your app to be relaunched to process an event. To run most location services in the background, you need to enable the location updates background mode in the Capabilities tab of your Xcode project. For services that launch your app, you need to request (and be granted) “Always” authorization from the user.

The standard location service delivers events normally while an app is running in the foreground. When your app is in the background, this service delivers events only when the location-updates background mode is enabled for the app. This service does not relaunch iOS apps that have been terminated.

The significant location change service delivers events normally while an app is running in the foreground or background. For a terminated iOS app, this service relaunches the app to deliver events. Use of this service requires “Always” authorization from the user.

The region monitoring service delivers events normally while an app is running in the foreground or background. (You can use this service for both geographic and beacon regions.) For a terminated iOS app, this service relaunches the app to deliver events. Use of this service requires “Always” authorization from the user.

Beacon ranging delivers events normally while an app is running in the foreground. When your app is in the background, this service delivers events only when the location-updates background mode is enabled for the app and the standard location service is running. (If the beacon region’s notifyEntryStateOnDisplay property is YES, waking the device causes the app to range for beacons for a few seconds in the background.) This service does not relaunch iOS apps that have been terminated; however, you can be relaunched by monitoring beacon regions using the region monitoring service.

The heading service delivers events normally while an iOS app is running in the foreground. When your app is in the background, this service delivers events only when the location-updates background mode is enabled for the app and the standard location service is running. This service does not relaunch iOS apps that have been terminated.

The visit service delivers events normally while an iOS app is running in the foreground. When your app is in the background, this service delivers events only when the location-updates background mode is enabled for the app and the standard location service is running. For a terminated iOS app, this service relaunches the app to deliver events. Use of this service requires “Always” authorization from the user.

Enabling the location-updates background mode ensures that an app continues to receive location events while in the background. When the app moves to the background, the system adds the location-services indicator to the status bar to let the user know that an app is using location services. The system may still terminate the app at any time to reclaim its memory or other resources.

Also from the doc,

Getting the Visited Locations In iOS, the visits service provides an alternative to the significant location change service for apps that need location information about interesting places that the user visited. For example, if the user is in one location for an extended period of time, the service might generate an event when the user arrives at that location and another when the user leaves that location. The service is intended for apps that might already be using the significant location change service and want an even lower power way to do so. You would not use this service to create navigation apps or apps that rely on regular location updates.

文档链接:

https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/index.html#//apple_ref/doc/uid/TP40007125-CH3-SW73

关于IOS 在应用程序终止而不使用 significantChange 时获取位置更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37450524/

相关文章:

ios - TableViewController 委托(delegate)没有被调用

html - 如何使白色div中的TEXT完全透明以显示背景?

ios - 从 Cllocation 获取 CLLocationCorrdinate2D 时出错

iOS - 如何在 Xcode 12.1 中添加 "Today Extension"目标?

ios - 如何从返回的 plist 数组中获取字符串

javascript - 移动菜单无法在 iPhone(Chrome 或 Safari)上打开

android - 通过挂起的 Intent 更改 Activity 的布局

Wpf面板背景问题

swift - 如何使用 SwiftUI 中的扩展将 Hashable 协议(protocol)添加到 CLLocationCoordinate2D

ios - 当用户允许位置跟踪时更新位置