如何使用私有API在iOS上运行后台进程来同步电子邮件,而无需越狱

我正在开发一个类似于联系人,日历的企业应用程序。 即使当我的应用程序在后台,我也想同步我的日历和联系人。 我也很擅长使用私有API,因为我不会提交给app store。 请注意,我想在不破解设备的情况下进行这项工作。

已经有一个类似的问题发布在这里我创build这个新的线程,因为已经发布了一个有一个解决schemebuild议越狱设备。

如果这是一个企业应用程序,而你没有提交给苹果,那么我会探讨让你的应用程序识别自己是一个VOIP应用程序。 然后你可以设置一个keepAliveTimer,并在后台得到定期的处理时间来做你所需要的。

我分享自己的问题的答案,因为这可能会帮助其他人

脚步:

1:在您的application-info.plist中添加“所需的背景模式”键,并将值设置为“App提供IP语音服务”。

2:在你的appdelegate.m文件中,像下面的代码片段一样实现“applicationDidEnterBackground:”方法。

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); }]; } 

在这里例如,我打印计数器variables在给定的时间间隔下面是输出日志消息:

 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 

如果您想连续运行,另一个想法是在Info.plist中启用所需的背景模式中的“audio”,并继续循环播放静音mp3,直到您想要继续运行。