Q:

Reset backgroundTimeRemaining when app goes to background

Using the following code I am able to run my background app for around 180 seconds. My final objective is to keep it running forever. Battery/processor overuse is not a concern for me as I'm making this for myself.
This is code I'm using to run my app in the background.
UIApplication * application = [UIApplication sharedApplication];
 
if([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)])
{
    NSLog(@"Multitasking Supported");
 
    __block UIBackgroundTaskIdentifier background_task;
    background_task = [application beginBackgroundTaskWithExpirationHandler:^ {
 
        //Clean up code. Tell the system that we are done.
        [application endBackgroundTask: background_task];
        background_task = UIBackgroundTaskInvalid;
    }];
 
    //To make the code block asynchronous
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 
        //### background task starts
        NSLog(@"Running in the background\n");
        while(TRUE)
        {
            NSLog(@"Background time Remaining: %f",[[UIApplication sharedApplication] backgroundTimeRemaining]);
            [NSThread sleepForTimeInterval:1]; //wait for 1 sec
        }
        //#### background task ends
 
        //Clean up code. Tell the system that we are done.
        [application endBackgroundTask: background_task];
        background_task = UIBackgroundTaskInvalid; 
    });
}
else
{
    NSLog(@"Multitasking Not Supported");
}

Background time remaining: starts at around 180 seconds and by the time it comes down to 5, the app gets suspended. No matter what I try, this cannot be avoided.
My device is running iOS 8.1 and here are the methods I've tried so far:
Method 1:
I set background modes as location in info.plist and used the following code as shown in this tutorial.
CLLocationManager * manager = [CLLocationManager new];
__block UIBackgroundTaskIdentifier background_task;
and then
[manager startUpdatingLocation];
Method 2:
Using the following lines of code before the app enters the background state.
CLLocationManager* locationManager = [[CLLocationManager alloc] init];
[locationManager startUpdatingLocation];
I just need to reset backgroundTimeRemaining and any hack will be fine. Thank you all.

A:

The way I solved this problem was following the updated part of this tutorial.

