[英]Significant Location updates after force quit in iOS app
I am currently tracking the user location updates for every mile travelled. 我目前正在跟踪每行驶一英里的用户位置更新。 And I have background mode turned on for app to look for location updates. 我已打开背景模式,以便应用程序查找位置更新。
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions:
[NSObject: AnyObject]?) -> Bool {
locationManager.delegate = self
if iOS8 {
locationManager.requestAlwaysAuthorization()
} else {
locationManager.startUpdatingLocation()
locationManager.stopUpdatingLocation()
}
locationManager.distanceFilter = 1609.34 // meters in 1 mile
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.pausesLocationUpdatesAutomatically = false
locationManager.startUpdatingLocation()
return true
}
But, I am wondering, if the application has been force quit, I would still like for the application to be updating the location. 但是,我想知道,如果该应用程序已被强制退出,我仍然希望该应用程序更新位置。 Is that possible with startUpdatingLocation
class? startUpdatingLocation
类是否可能? Or should I be using startMonitoringSignificantLocationChanges
还是我应该使用startMonitoringSignificantLocationChanges
I read the doc here but didn't quite understand when to move from startUpdatingLocation
to startMonitoringSignificantLocationChanges
when/while the app is being force quit. 我在这里阅读了文档,但是当应用程序被强制退出时,我还是不太明白何时从startUpdatingLocation
到startMonitoringSignificantLocationChanges
。 Should it be under applicationWillTerminate
function ? 应该在applicationWillTerminate
函数下吗?
Or if that is even possible or is there something else i should be doing. 或者,即使这是可能的,或者还有其他我应该做的事情。
UPDATE: 更新:
In most cases, the system does not relaunch apps after they are force quit by the user. 在大多数情况下,系统在用户强行退出应用后不会重新启动应用。 One exception is location apps, which in iOS 8 and later are relaunched after being force quit by the user. 位置应用程序是一个例外,位置应用程序在iOS 8及更高版本中被用户强行退出后重新启动。 In other cases, though, the user must launch the app explicitly or reboot the device before the app can be launched automatically into the background by the system. 但是,在其他情况下,用户必须明确启动应用程序或重新启动设备,然后系统才能将应用程序自动启动到后台。
If thats the case, should I use startUpdatingLocation
or move to startMonitoringSignificantLocationChanges
? 如果是这样,我应该使用startUpdatingLocation
还是移至startMonitoringSignificantLocationChanges
?
If the app was terminated, you could not run any program for the app. 如果该应用程序终止,则无法为该应用程序运行任何程序。
And it's not always to handle applicationWillTerminate function when the app was terminated. 当应用终止时,并不总是要处理applicationWillTerminate函数。 In some situations, the system kills the app without any notification. 在某些情况下,系统会在没有任何通知的情况下终止该应用程序。 Please read the document about application life cycle. 请阅读有关应用程序生命周期的文档。
https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/TheAppLifeCycle/TheAppLifeCycle.html https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/TheAppLifeCycle/TheAppLifeCycle.html
I think you want to do your app is running like a daemon service. 我想您想让您的应用像守护程序一样运行。 iOS does not allow us that unless the device is jail broken. iOS不允许我们这样做,除非设备被越狱。
https://www.chrisalvares.com/blog/7/creating-an-iphone-daemon-part-1/ https://www.chrisalvares.com/blog/7/creating-an-iphone-daemon-part-1/
If you are care of the device battery, you would to do like this. 如果您需要保养设备电池,则可以这样做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.