ios - How to pause (and resume) background location monitoring when low battery? -


i'm writing location tracking application ios 7.1 (iphone) requires stop or pause background location monitoring when battery 30% , lower. location monitoring should resume in background when battery improves. how can this? i'm using significant location change update (cllocationmanager api methods) background location monitoring.

thanks!

as per documentation of startmonitoringsignificantlocationchanges:

if start service , application subsequently terminated, system automatically relaunches application background if new event arrives. in such case, options dictionary passed application:didfinishlaunchingwithoptions: method of application delegate contains key uiapplicationlaunchoptionslocationkey indicate application launched because of location event. upon relaunch, must still configure location manager object , call method continue receiving location events. when restart location services, current event delivered delegate immediately. in addition, location property of location manager object populated recent location object before start location services.

first step :-

so when application launch in background check launch option key uiapplicationlaunchoptionslocationkey.then know application launch cause of location event.

the application tracks location updates in background, purged, , has been relaunched. in case, dictionary contains key indicating application relaunched because of new location event.

second step :- battery %

//this give battery between 0.0 (empty) , 1.0 (100% charged) [[uidevice currentdevice] setbatterymonitoringenabled:yes]; float batterylevel = [[uidevice currentdevice] batterylevel];  //if want percentage, can this: batterylevel *= 100; 

third step :- check application state ( if required so)

if application in background next step

[uiapplication sharedapplication].applicationstate == uiapplicationstatebackground 

fourth step :- stop monitoring significant location change

apply check battery percentage , if less 30%, stop monitoring location update.

if find battery level more 30% , location monitoring not enabled startmonitoringlocationupdate

this check can done in didupdatetolocation:fromlocation , may @ application become active or per application requirement.

hope helps ...!!!


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -