iOS 7 Background transfer service stops after 3 minutes

Viewed 4937

I have created a sample code to download a file from network repeatedly(every 30 secs or so). In iOS 7 using Background transfer services with NSURLSession
I followed this tutorial http://mobile.tutsplus.com/tutorials/iphone/ios-7-sdk-background-transfer-service/ and added a timer like this to repeat it.

    [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:nil];
mute = [NSTimer scheduledTimerWithTimeInterval:30.0f
                                        target:self
                                      selector:@selector(startDownload)
                                      userInfo:nil
                                       repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:mute forMode:NSRunLoopCommonModes];

When I run it(in background by clicking home button) in simulator and on iPad connected to the Xcode(where I can see the logs) everything works fine and it keeps downloading continuously. But when I disconnect the iPad from the Mac and run it on the iPad in background after around 3 seconds it stops running (handleEventsForBackgroundURLSession in AppDelegate get called).

In Xcode project capabilities I have selected Background fetch as Background Modes.

What am I missing here or what have I done wrong so that it gets stop after around 3 minutes? (According to the documentations with iOS 7 Background transfer services it should run continuously as there's no time limit in background for this.)

Thanks

5 Answers
Related