I'm developing an iOS app that updates data to server every minute. I wants to work this data update even when app goes to background. I've enabled the "Background mode" in "capabilities" and not checked any background options. Also used the below code
UIApplication* app = [UIApplication sharedApplication];
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
NSLog(@"beginBackgroundTaskWithExpirationHandler");
//[app endBackgroundTask:bgTask];
//bgTask = UIBackgroundTaskInvalid;
}];
Imp : I've commented the [app endBackgroundTask:bgTask]
and bgTask = UIBackgroundTaskInvalid
.
Now my app working well in background.
My query is,Is there any chance to reject my app from App Store due to this ?
When you use this background task, it only runs for a few minutes. (Test this on a device, not connected through Xcode. If you're testing this on simulator, you can get lulled into a sense of apps continuing to run in background, when in the real world, they won't.)
Apple only allows ongoing background operation for a very narrow set of apps (navigation, music, VOIP, etc.). For background network requests, there are background
NSURLSession
sessions (to carry on with long running downloads/uploads, not to repeatedly initiate new requests). It also has background fetch, for opportunistically initiating requests at the discretion of the OS, not at any predetermined schedule, and certainly not every minute.Bottom line, Apple will not allow apps that somehow circumvent these narrowly defined scenarios. Besides, you can kill a user's battery and use up their cell data plan if you constantly initiated new requests.