Keeping the app in background mode for continuos location updates

跟風遠走 提交于 2020-01-02 12:26:41

问题


My project is using a CLLocationManager object, receiving updates via: locationManager:didUpdateToLocations:

I want these updates even though my app is in the background. So in info.plist i have set the, "Required background modes" list to App registers for location updates.

But my testing shows that it does not receive the updates in background state.

However, i'm not sure i'm having the correct perception of background state/ suspended state. This is how i think it works:

After the home button is pressed, the app enters background mode for 5 seconds, 
and then enter suspended state.

I guess this is why it's not working. But if setting the info.plist to ""app registers for location updates" does not keep the app from reaching suspended state, then how do i achieve it?

What is the difference (if any) in pressing the Home button and pressing the lock button? State-wise i mean.

I have read the relevant parts of this guide: http://www.raywenderlich.com/29948/backgrounding-for-ios

Im still new to IOS, so i might have overlooked something.


回答1:


First, have you studied "Getting Location Events in the Background" in the Location and Maps Programming Guide?

Have you checked backgroundRefreshStatus? Is this app allowed to run in the background according to it?

What is the value of pausesLocationUpdatesAutomatically?

What accuracy are you requesting? Are you moving sufficiently to generate changes over that accuracy?

Did you call startUpdatingLocation?

Is this iOS 6 or 7? If iOS 7, make sure to watch Session 204: "What’s New with Multitasking?" There have been several changes and iOS is now more aggressive about shutting down apps than it was previously.



来源:https://stackoverflow.com/questions/18925845/keeping-the-app-in-background-mode-for-continuos-location-updates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!