swift - iOS why system kills the app using location in backround -


i have app uses location updates when in foreground in background. using corelocation framework, have implemented app location updates sent server after every 5 minutes, using this code reference.

this works fine in foreground, when app goes background, getting killed os after 30 minutes hour. want app updates @ least 8 hours, in background.

also, app using 10% of battery per hour. related app being killed in background? if so, how can resolve battery problem? otherwise, can tell me issue is?

below crash log device:

exception type:  00000020 exception codes: 0x000000008badf00d exception note:  simulated (this not crash) highlighted thread:  2  application specific information: <bknewprocess: 0x17e74840; com.app.app; pid: 560; hostpid: -1> has active assertions beyond permitted time:  {( <bkprocessassertion: 0x17d78740> id: 560-c9e81e97-90d9-4f95-871e-3dc53372f302 name: called uikit, <redacted> process: <bknewprocess: 0x17e74840; com.app.example; pid: 560; hostpid: -1> permittedbackgroundduration: 180.000000 reason: finishtask owner pid:560 preventsuspend  preventidlesleep  preventsuspendonsleep , <bkprocessassertion: 0x17e6a870> id: 560-bd7b29fc-dabc-42ff-af17-b277bdb1c59d name: called uikit, <redacted> process: <bknewprocess: 0x17e74840; com.app.example; pid: 560; hostpid: -1> permittedbackgroundduration: 180.000000 reason: finishtask owner pid:560 preventsuspend  preventidlesleep  preventsuspendonsleep  )} 

for background task use following function:

func backgroundtask(){     var application=uiapplication.sharedapplication()     var background_task: uibackgroundtaskidentifier?     background_task = application.beginbackgroundtaskwithexpirationhandler({() -> void in         application.endbackgroundtask(background_task!)         background_task = uibackgroundtaskinvalid     })     dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_default, 0), {() -> void in         //run app without startupdatinglocation. backgroundtimeremaining decremented 600.00         self.locationmanager.startupdatinglocation()         while (true) {             //backgroundtimeremaining time not go down.             print("background time remaining: \(uiapplication.sharedapplication().backgroundtimeremaining)")             nsthread.sleepfortimeinterval(1)              break             //wait 1 sec         }         application.endbackgroundtask(background_task!)         background_task = uibackgroundtaskinvalid     })  } 

when app enters in background state switch significant location updates , app receive location update continuously. can call startmonitoringsignificantlocationchanges on cllocationmanger's object think. , not need establish background task think.

check apple documentation, states,

if start service , app subsequently terminated, system automatically relaunches app background if new event arrives. in such case, options dictionary passed application:willfinishlaunchingwithoptions: , application:didfinishlaunchingwithoptions: methods of app delegate contains key uiapplicationlaunchoptionslocationkey indicate app 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

so, solve problem think , solve issue of battery also.

second thing (for battery consumption), should not set desiredaccuracy kcllocationaccuracybest when want update location in background long time. can set kcllocationaccuracythreekilometers desiredaccuracy , can set setdistancefilter big digit 99999 when enter in background.

you can refer this post , this post.

hope :)


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -