Background task is running only when iPhone is connected with xcode -
hi using following code background task works fine ,when iphone connected xcode , when ran app without connected xcode ,then background tasks won't work
- (void)applicationdidenterbackground:(uiapplication *)application { back=1.0f; nsautoreleasepool *pool=[[nsautoreleasepool alloc] init]; nsrunloop *runloop=[nsrunloop currentrunloop]; timer=[nstimer scheduledtimerwithtimeinterval:1.0 target:self selector:@selector(changecounter) userinfo:nil repeats:yes]; [runloop run]; [pool release]; }
please why happening
have checked documentation background executation?
you should start task like:
- (void)applicationdidenterbackground:(uiapplication *)application { uiapplication* app = [uiapplication sharedapplication]; bgtask = [app beginbackgroundtaskwithexpirationhandler:^{ [app endbackgroundtask:bgtask]; bgtask = uibackgroundtaskinvalid; }]; // start long-running task , return immediately. dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_default, 0), ^{ // work associated task. [app endbackgroundtask:bgtask]; bgtask = uibackgroundtaskinvalid; }); }
Comments
Post a Comment