how to run background process on the iOS using pri

2019-02-10 03:17发布

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.

3条回答
我命由我不由天
2楼-- · 2019-02-10 03:25

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.

查看更多
冷血范
3楼-- · 2019-02-10 03:28

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.

查看更多
乱世女痞
4楼-- · 2019-02-10 03:36

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
查看更多
登录 后发表回答