You do not need to set that requirement for background modes. You can try on applicationDidEnterBackground:
call startBackgroundTask
- (void)startBackgroundTask {
if(bgTask != UIBackgroundTaskInvalid){
[[UIApplication sharedApplication] endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}
bgTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
NSLog(@"your time is over");
//you can call start once again to get more time
}];
}
Where the bgTask
is UIBackgroundTaskIdentifier bgTask;
My only worry would be that from my observations to get another time for background execution user has to touch the screen to make screen illuminating (screen can be locked). To make sure your code is working in background you can set up a timer and log a message on the console periodically (for example time remaining which system gave you on the background execution [UIApplication sharedApplication].backgroundTimeRemaining
or restarting bluetooth). As far as I know it is quite common approach to that kind of problems.