如何在ios5的后台运行我的应用程序每30秒运行一次?

时间:2012-02-07 05:40:35

标签: iphone ios ios5

我在ios5中实现了长时间运行的进程方法。当我的应用程序在后台时,我想每隔30秒或1分钟激活一些功能。我已经编写了执行长时间运行过程的代码,输入后台方法,输入后我无法执行定时器功能背景。我应该把我的计时器功能放在哪里,以便它应该调用目标方法,即使它在后台。

 bgTask = [application beginBackgroundTaskWithExpirationHandler:^{
    // Clean up any unfinished task business by marking where you.
    // stopped or ending the task outright.

    [application endBackgroundTask:bgTask];
    bgTask = UIBackgroundTaskInvalid;
}];


dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

   [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(targetMethod) userInfo:nil repeats:YES];        
   [application endBackgroundTask:bgTask];
    bgTask = UIBackgroundTaskInvalid;
});

怎么做?一些示例代码会有所帮助。

由于 普什帕

1 个答案:

答案 0 :(得分:4)

您只能在后台支持位置服务。音频播放和VOIP服务。 如果你的应用程序没有使用任何这些API及其功能..请不要浪费你的时间去做...即使有一些方法可以实现这一点,Apple也不会接受你的应用程序。

相关问题