UIBackgroundModes位置和重要的位置变化与区域监测 [英] UIBackgroundModes location and significant location changes with region monitoring

查看:96
本文介绍了UIBackgroundModes位置和重要的位置变化与区域监测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,它使用 startMonitoringForRegion: startMonitoringSignificantLocationChanges 的组合来了解用户的位置当应用程序在后台时。这是否意味着我需要在信息中包含 UIBackgroundModes 键的 location 值.plist

I have an app that uses a combination of startMonitoringForRegion: and startMonitoringSignificantLocationChanges to keep aware of where the user is when the app is in the background. Does this mean that I need to include the location value for the UIBackgroundModes key in the Info.plist?

这是来自文档的引用:


对于不需要高精度位置数据的应用,强烈建议使用重要更改位置服务。使用此服务,仅当用户的位置发生显着变化时才会生成位置更新;因此,它非常适合为用户提供非关键,位置相关信息的社交应用或应用。如果在更新发生时暂停应用程序,系统会在后台将其唤醒以处理更新。如果应用程序启动此服务然后终止,则系统会在新位置可用时自动重新启动应用程序。此服务在iOS 4及更高版本中可用,并且仅适用于包含蜂窝无线电的设备。

The significant-change location service is highly recommended for apps that do not need high-precision location data. With this service, location updates are generated only when the user’s location changes significantly; thus, it is ideal for social apps or apps that provide the user with noncritical, location-relevant information. If the app is suspended when an update occurs, the system wakes it up in the background to handle the update. If the app starts this service and is then terminated, the system relaunches the app automatically when a new location becomes available. This service is available in iOS 4 and later, and it is available only on devices that contain a cellular radio.

...

为用户提供连续位置更新的应用程序(即使在后台)可以通过在其Info.plist文件中包含UIBackgroundModes键(具有位置值)来启用后台位置服务。在UIBackgroundModes键中包含此值并不妨碍系统暂停应用程序,但它确实告诉系统,只要有新的位置数据要传递,它就应该唤醒应用程序。因此,这个密钥有效地让应用程序在后台运行,以便在它们发生时处理位置更新。

An app that provides continuous location updates to the user (even when in the background) can enable background location services by including the UIBackgroundModes key (with the location value) in its Info.plist file. The inclusion of this value in the UIBackgroundModes key does not preclude the system from suspending the app, but it does tell the system that it should wake up the app whenever there is new location data to deliver. Thus, this key effectively lets the app run in the background to process location updates whenever they occur.

我对此的解释是 location UIBackgroundModes 键的值仅在应用需要连续位置更新时才需要,例如sat导航应用。

My interpretation of this is that the location value for the UIBackgroundModes key is only required if the app needs continuous location updates, like a sat nav app.

我还尝试在没有 UIBackgroundModes的 location 值的设备上运行该应用程序键,它会继续报告重要的位置更改以及输入退出区域的时间。

I have also tried running the app on a device without the location value for the UIBackgroundModes key and it continues to report significant location changes and when the a region is entered of exited.

此外,唯一的地方是 UppackgroundModes CLLocationManager类参考 startUpdatingLocation 讨论中,我没有使用。

Also, the only place that UIBackgroundModes is mentioned in the CLLocationManager Class Reference is in the startUpdatingLocation discussion, which I am not using.

推荐答案

您说得对的位置键,当你的应用程序需要高精度的位置,即使在后台更新时,它才是必需的。像Runkeeper这样的东西使用它来允许它跟踪你的位置,即使你正在使用多任务的另一个应用程序。 来自iOS密钥的文档: UIBackgroundModes

You're right about the location key, it's only required when your app needs high-precision location updates even when in the background. Something like Runkeeper uses this to allow it to keep tracking your location, even when you're using another app with multitasking. From the docs for iOS Keys: UIBackgroundModes


location:该应用程序提供基于位置的信息给用户并要求
使用标准位置服务(而不是
重要的更改位置服务)来实现此功能。

"location": The app provides location-based information to the user and requires the use of the standard location services (as opposed to the significant change location service) to implement this feature.


如果存在在后台运行的替代方案,则应使用这些替代方案。例如,应用可以使用有意义的位置更改界面来接收位置事件,而不是注册为后台位置应用。

Where alternatives for running in the background exist, those alternatives should be used instead. For example, apps can use the signifiant location change interface to receive location events instead of registering as a background location app.

区域监控将没有位置键的工作。事实上,区域监控可以在没有启用任何特殊iOS密钥的情况下工作。

Region monitoring will work without the location key. In fact, region monitoring will work without any special iOS keys being enabled.

你说你没有使用 CLLocationManager ,但如果您正在使用区域监控,则必须使用该类。您需要为应用设置位置管理器代理,以实际获取区域通知。

You say that you're not using CLLocationManager, but if you're using region monitoring, you'll have to use that class. You need to set up a location manager delegate for your app to actually get the region notifications.

这篇关于UIBackgroundModes位置和重要的位置变化与区域监测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆