Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to run background process on the iOS using private APIs to sync email items without jailbreaking the phone

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'm good to use private API's also, as I'm not going to submit to the app store. Note here is, i wanted to make this work without jailbreaking the device.

Aalready a similar question posted here I'm creating this new thread since the already posted one has a solution suggested for Jailbreaked device.

like image 687
shatthi Avatar asked Aug 17 '12 10:08

shatthi


2 Answers

I'm sharing the answer for my own question as this might help others

Steps:

1: Add "Required background modes" key in your application-info.plist and assign value as "App provides Voice over IP services" to its item.

2: In your appdelegate.m file, implement the "applicationDidEnterBackground:" method as below code snippet.

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
like image 61
shatthi Avatar answered Oct 20 '22 01:10

shatthi


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.

like image 35
onnoweb Avatar answered Oct 19 '22 23:10

onnoweb