i developed an app which ranges for beacons in the background using ibeacon API. As it uses the core location and bluetooth , so i enabled the Location, Bluetoothconfiguration from the capabilities. So after running my app , ranging happening in background, but after 5-10 min between my app terminates, when i launch the app it is again showing the splash and the login page, so after google i learned that app runs in background with some extra time.
To overcome the app termination i'm using the below code in a method and calling that method in applicationDidEnterBackground.
-(void)startBackgroundTask
{
if(bgTask != UIBackgroundTaskInvalid)
{
[[UIApplication sharedApplication] endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}
bgTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
[self endBackgroundUpdateTask];
NSLog(@"your time is over");
//you can call start once again to get more time
}];
}
-(void) endBackgroundUpdateTask
{
[[UIApplication sharedApplication] endBackgroundTask: bgTask];
bgTask= UIBackgroundTaskInvalid;
[[NSNotificationCenter defaultCenter]
postNotificationName:@"TimerOutStartMonitering" object:nil];
}
After using the above code and debugging , my app ranging stops once the UIBackgroundTaskInvalid. How can i achieve the both tasks 1)My App shouldn't terminate once the background time is finished. 2)My ranging for beacons shouldn't stop.
Is it possible? Please help me out.