objective c - iOS: Why is the ViewController called when the app runs in background mode after terminated? -


i made application monitors updated location in background after terminated moves. in order implement app, made location manager class including <corelocation/corelocation.h> , cllocationmanagerdelegate , enabled 'location updates' , 'background fetch' modes in capabilities. , in order checking out, added node.js module connected remote server, , application send message remote server when new location updated in background (after terminated, not remained in suspended apps queue). , location manager declared , called in viewdidload of viewcontroller.

the question why viewcontroller called when app runs in background mode after terminated above flow? thought location manager called because contains cllocationmanagerdelegate, wrong. background task started viewdidload method.

dose know why happened? want know functions called beginning in background mode after terminated.

edit:

here codes updating current location in background after terminated. added capabilities 'location updates' , 'background fetch'.

  1. viewcontroller.m (viewdidload method)

    [super viewdidload];

    locationmanager = [[locationmanager alloc] initwithdelegate:self]; uiapplicationstate state = [[uiapplication sharedapplication] applicationstate]; switch(state){ case uiapplicationstateactive: case uiapplicationstateinactive: [locationmanager startlocationservice:no]; break; case uiapplicationstatebackground: [locationmanager startlocationservice:yes]; break; }

  2. locationmanager.m (init method)

    iscalledafterterminated = flag; if(!socketio.isconnected){ [socketio connect]; } locationmanager = [[cllocationmanager alloc] init]; if ([locationmanager respondstoselector:@selector(requestalwaysauthorization)]){ [locationmanager requestalwaysauthorization]; } // ios 9 if ([locationmanager respondstoselector:@selector(setallowsbackgroundlocationupdates:)]){ [locationmanager setallowsbackgroundlocationupdates:yes]; } locationmanager.delegate = self; locationmanager.pauseslocationupdatesautomatically = no; if(iscalledafterterminated){ locationmanager.desiredaccuracy = kcllocationaccuracyhundredmeters; locationmanager.distancefilter = distance_filter_terminated; [locationmanager startmonitoringsignificantlocationchanges]; } else { locationmanager.desiredaccuracy = kcllocationaccuracybest; locationmanager.distancefilter = distance_filter_running; [locationmanager startupdatinglocation]; }


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -