objective c - How do I get a background location update every n minutes in my iOS application? -
i'm looking way background location update every n minutes in ios application. i'm using ios 4.3 , solution should work non-jailbroken iphones.
i tried / considered following options:
cllocationmanager startupdatinglocation/startmonitoringsignificantlocationchanges
: works in background expected, based on configured properties, seems not possible force update location every n minutesnstimer
: work when app running in foreground doesn't seem designed background tasks- local notifications: local notifications can scheduled every n minutes, it's not possible execute code current location (without user having launch app via notification). approach doesn't seem clean approach not notifications should used for.
uiapplication:beginbackgroundtaskwithexpirationhandler
: far understand, should used finish work in background (also limited in time) when app moved background rather implementing "long-running" background processes.
how can implement these regular background location updates?
i found solution implement of apple developer forums:
- specify
location background mode
- create
nstimer
in backgrounduiapplication:beginbackgroundtaskwithexpirationhandler:
- when
n
smalleruiapplication:backgroundtimeremaining
work fine. whenn
larger,location manager
should enabled (and disabled) again before there no time remaining avoid background task being killed.
this works because location 1 of 3 allowed types of background execution.
note: lost time testing in simulator doesn't work. however, works fine on phone.
Comments
Post a Comment