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

标签 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;
});

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

谢谢
普什帕

最佳答案

您只能在后台支持定位服务,音频播放和VOIP服务。
如果您的应用程序不使用这些API及其功能中的任何一个,那么请不要浪费您的时间...即使有某种方法,Apple也不会接受您的应用程序。

关于iphone - 如何在ios5中每30秒在后台运行我的应用程序一次?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9171508/

相关文章:

iphone - 检测 AVFoundation 相机何时完成对焦

iphone - 当 contentOffset 有值时,Scrollview 的位置在动画过程中跳跃

ios - 没有可见的@interface 'PhotosTableViewController'声明选择器 'viewWithImageName'

ios - [_UIBarItemAppearance setTitleColor:forState:]:无法识别的选择器已发送到实例

ios - 无法通过 segue 传递变量(Swift)

ios - NSArray 错误 : NSCFArray objectAtIndex index (5) beyond bounds (5)

ios - 带有奇怪语言的 Facebook iOS SDK Feed 对话框确认按钮

xcode - iPad 不显示在 xcode 中

iphone - Viddy 如何实现可下载过滤器?

ios - 在应用程序启动时, subview 在设备的不同初始方向上采用不同的帧大小