Getting user location when app is in background. IOS -
i'm developing app works in background user's location , send server using http requests. first intention user's location every n minutes, after alot of research , trial, gave since ios kills background tasks after 3 minutes.
then tried working on monitoringsignificantlocationchanges, inaccurate location updates due cell tower usage ruins purpose of app.
a solution of following appreciated:
- getting user's location in background every n minutes infinitely.
- getting user's location in background on significantlocationchanges high accuracy(using gps)
- any other background solution high accuracy results.
this works me, use cllocationmanagerdelegate, register updates on didupdatelocations , in app delegate
- (void)applicationdidbecomeactive:(uiapplication *)application { [_locationmanager stopmonitoringsignificantlocationchanges]; [_locationmanager startupdatinglocation]; }
i start updating location, key me, when app goes background switch significant location changes app doesn't drain batter this:
- (void)applicationdidenterbackground:(uiapplication *)application { [_locationmanager startmonitoringsignificantlocationchanges]; }
in didupdatelocations, can check
bool isinbackground = no; if ([uiapplication sharedapplication].applicationstate == uiapplicationstatebackground) { isinbackground = yes; }
and start task in background report location example
if (isinbackground) { [self sendbackgroundlocationtoserver:self.location]; }
and start task, hope helps.
Comments
Post a Comment