CLLocationManager startMonitoringForRegion:设备重新启动后不重新启动应用程序 [英] CLLocationManager startMonitoringForRegion: not relaunching app after device restart
问题描述
好,所以我目前有一个应用程序,在其中注册了要使用 CLLocationManager
startMonitoringForRegion
方法监视的地理围栏。当应用程序位于前台和后台时,此方法可以正常工作。
Ok, so I currently have an app where I register a geofence to be monitored using the CLLocationManager
startMonitoringForRegion
method. This works fine when the app is in the foreground and background.
我还设置了适当的plist值:
I also have the appropriate plist values set:
UIBackgroundModes :{location}
UIRequiredDeviceCapabilities: {location-services}
什么不起作用
重新启动设备后,不会重新启动该应用程序。如果我在进入后台之前设置了 startMonitoringSignificantLocationChanges
,就可以强制这种情况发生。但是这种方法会消耗更多的电池电量,而且只要我打破地理围栏就不需要一直使用该位置。
What doesn't work
After a device restart, the app is not being relaunched. I can force this to happen if I set startMonitoringSignificantLocationChanges
before entering background. But this method uses much more battery life and I don't need the location all the time, just whenever I break a geofence.
区域文档说:
在iOS中,您向位置管理器注册的区域在应用程序启动之间持续存在。如果您的iOS应用未运行时发生区域交叉,系统会在后台自动将其唤醒(或重新启动),以便其可以处理事件。重新启动后,您先前创建的所有区域都将在您创建的任何位置管理器对象的MonitoredRegions属性中可用。
是否可以(在使用地理围栏区域时)使系统在系统重启后重启我的应用,而无需使用 startMonitoringSignificantLocationChanges
吗?
Is it possible (when using geofencing regions) to have the system restart my app AFTER a system reboot, WITHOUT using startMonitoringSignificantLocationChanges
?
编辑:我的目标是iOS6& iOS7
I am targeting iOS6 & iOS7
推荐答案
在这里回答我自己的问题。
Answering my own question here.
需要使用 startMonitoringSignificantLocationChanges
来使系统在设备重启后唤醒应用程序。如果用户强行关闭应用,则不会唤醒应用。
While you do need to use the startMonitoringSignificantLocationChanges
to get the system to wake up the app after a device reboot. Nothing will wake up the app if the user has force closed it.
出于我的目的,我不需要设置 UIBackgroundModes
到位置
。此设置通常用于只需要细粒度位置更新的应用程序(例如,使用 startUpdatingLocation
)。使用 startMonitoringSignificantLocationChanges
时,不需要设置背景模式。
For my purposes, I did not need to set UIBackgroundModes
to location
. This setting is usually used for applications that only need fine-grained location updates (E.g. using startUpdatingLocation
). Setting the background mode is not required when using startMonitoringSignificantLocationChanges
.
这篇关于CLLocationManager startMonitoringForRegion:设备重新启动后不重新启动应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!