简体   繁体   中英

Updating location from the background in ios 7?

I have an iOS app that use the location services.

I need to call StartUpdatingLocation() while the app is in the background at a specific time (ie 4/17/2014 at 3:00 pm).

Previously I tried using a timer to do this, but found out that you can't run a timer while the app is in the background on iOS 7. Currently I'm running the location services when the app is initially booted and slowly updating it every so often. With each update, I check if the specific start time has been reached yet and if so I start logging the coordinates to the database.

Is there a more efficient/less data and battery intensive way to have location services start from the background of an iOS 7 application?

I've also considered using LocationUpdatesPaused and LocationUpdatesResumed events to help reduce the battery and data usage, while checking for my specific date and time.

I've consulted this helpful link: http://gooddevbaddev.wordpress.com/2013/10/22/ios-7-running-location-based-apps-in-the-background/

You can't do this.

Apple explicitly state in their documentation you should not call StartUpdatingLocation() while in the background. Apparently you used to be able to do this and it worked before iOS7 but I tried it with iOS7 and it doesn't work, so if it used to be possible it now no longer is.

But apart from that, with iOS there is no way of scheduling an action at a particular time in the background to occur anyway.

What you could do is change the accuracy to low (in combination with pausing updates etc.) when you don't need location updates and set it to high when you do to preserve battery life, but you cannot do this at a specific time when in the background.

iOS supports background location services as long as you declare them in your info.plist file like so:

...
<key>UIBackgroundModes</key>
    <array>
        <string>location</string>
    </array>
...

However, Apple is very fussy about the types of app it will approve with this behaviour because of battery life implications.

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