I want to make my Application Active when Application is in background state, as my NStimer and other operation are performing. So, I did the following code to make my Application Active.
- (void)applicationWillResignActive:(UIApplication *)application
{
UIApplication *app = [UIApplication sharedApplication];
if (backgroundTaskBool==TRUE)
{
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
dispatch_async(dispatch_get_main_queue(), ^{
if (bgTask != UIBackgroundTaskInvalid)
{
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}
});
}];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// Do the work associated with the task.
_locationManager.distanceFilter = 100;
_locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
[_locationManager startMonitoringSignificantLocationChanges];
[_locationManager startUpdatingLocation];
dispatch_async(dispatch_get_main_queue(), ^{
if (bgTask != UIBackgroundTaskInvalid)
{
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}
});
});
}
}
I just wanted to know is it a correct way to do? or there will be some other way to achieve this, because this process is taking too much battery and unnecessary location updating. So please help me out from this.
Thanks in advance.