【问题标题】:How to countinue an task in when the app enters backgroudn in iphone当应用程序在iphone中进入后台时如何继续任务
【发布时间】:2012-11-27 08:48:47
【问题描述】:

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

【问题讨论】:

    标签: iphone objective-c ios5 ios4 ios6


    【解决方案1】:

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

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

    【讨论】:

    • 这是答案还是您在添加问题?谢谢
    • 这是我想出的答案
    猜你喜欢
    • 1970-01-01
    • 2019-03-11
    • 1970-01-01
    • 1970-01-01
    • 2020-07-17
    • 1970-01-01
    • 2014-12-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多