简体   繁体   中英

How to get current location latitude and longitude if application running in Background?

I am Working with CLLocation manager,

I have implemented startUpdatingLocation method for getting current location latitude and longitude.

I got latitude and longitude of current location if application running Foreground but, when application running in Background it's not work.

Please suggest me how i got the current location latitude and longitude if application running in Background.

i just found answer in stackoverflow from this link:-

How do I get a background location update every n minutes in my iOS application?

Found a solution to implement this with the help of the Apple Developer Forums. I did the following:

  • Specify location background mode
  • Use an NSTimer in the background by using UIApplication:beginBackgroundTaskWithExpirationHandler:
  • In case n is smaller than UIApplication:backgroundTimeRemaining it does works just fine, in case n is larger, the location manager should be enabled (and disabled) again before there is no time remaining to avoid the background task being killed. This does work since location is one of the three allowed types of background execution.

Note : Did loose some time by testing this in the simulator where it doesn't work, works fine on my phone.

在backround中获取当前位置在plist中指定位置背景模式。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM