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

前端 未结 3 1644
攒了一身酷
攒了一身酷 2021-01-02 21:28

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\

相关标签:
3条回答
  • 2021-01-02 21:38

    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
    
    0 讨论(0)
  • 2021-01-02 21:44

    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.

    0 讨论(0)
  • 2021-01-02 21:44

    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.

    0 讨论(0)
提交回复
热议问题