I\'m working on an enterprise application, which is similar to contacts, calendar. I would like to sync my calendar and contact even when my application is in background. I\
I'm sharing the answer for my own question as this might help others
Steps:
static int counter;
- (void)applicationDidEnterBackground:(UIApplication *)application
{
//Minimun keepAliveTimeout is 600 seconds
[[UIApplication sharedApplication] setKeepAliveTimeout:605 handler:^{
//do your task
counter ++;
NSLog(@"Counter # %d", counter);
}];
}
Here for example, i'm printing the counter variable in the given time interval Below is the Output Log message:
2012-08-27 14:06:09.216 BackgroundApplicationForVOIP[1129:207] Counter # 1
2012-08-27 14:16:14.218 BackgroundApplicationForVOIP[1129:207] Counter # 2
2012-08-27 14:26:19.219 BackgroundApplicationForVOIP[1129:207] Counter # 3
2012-08-27 14:36:24.220 BackgroundApplicationForVOIP[1129:207] Counter # 4
2012-08-27 14:46:29.221 BackgroundApplicationForVOIP[1129:207] Counter # 5
2012-08-27 14:54:21.000 BackgroundApplicationForVOIP[1129:207] Counter # 6
2012-08-27 15:19:48.099 BackgroundApplicationForVOIP[1129:207] Counter # 7
2012-08-27 15:26:03.201 BackgroundApplicationForVOIP[1129:207] Counter # 8
2012-08-27 15:39:50.167 BackgroundApplicationForVOIP[1129:207] Counter # 9
2012-08-27 16:07:28.112 BackgroundApplicationForVOIP[1129:207] Counter # 10
2012-08-27 16:13:43.217 BackgroundApplicationForVOIP[1129:207] Counter # 11
2012-08-27 16:23:48.218 BackgroundApplicationForVOIP[1129:207] Counter # 12
2012-08-27 16:33:53.219 BackgroundApplicationForVOIP[1129:207] Counter # 13
2012-08-27 16:43:58.220 BackgroundApplicationForVOIP[1129:207] Counter # 14
2012-08-27 16:54:03.221 BackgroundApplicationForVOIP[1129:207] Counter # 15
If this is an enterprise app and you're not submitting to Apple then I would explore having your app identify itself as a VOIP app. Then you can set a keepAliveTimer and get get periodic processing time in the background to do what you need.
If you want to run continuously, another idea is to enable "audio" in Required Background modes in Info.plist and keep on looping a silent mp3 till you want to keep running.