2

即使应用程序在退出 iPhone (iOS) 中的活动状态时进入后台,我如何才能运行任务直到完成。

4

1 回答 1

4

首先我们需要检查设备是否支持多任务处理??

if([UIDevice currentDevice]respondsToSelector:@selector(isMultitaskingSupported)){

  //  If the device supports Multitasking we can run the task as :-

    UIBackgroundTaskIdentifier bgTask;

    bgTask=[[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
        [[UIApplication sharedApplication] endBackgroundTask:bgTask];
    }];

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul), ^{
        for(double i=0; i<99999; i++)
            NSLog(@"Backgroudn quee");

        [[UIApplication sharedApplication] endBackgroundTask:bgTask];
    });
}
于 2012-11-27T08:51:24.013 回答