当应用程序进入后台时,请继续运行NSOperationQueue

问题描述 投票:3回答:2

我正在使用NSOperation下载文件并添加为NSOperationQueue。当应用在后台运行时,NSOperationQueue被暂停。如果队列不会在后台挂起并开始下一个操作,是否可以解决?

ios multithreading grand-central-dispatch nsoperation nsoperationqueue
2个回答
6
投票

当队列正在运行时,请使用UIApplication beginBackgroundTaskWithExpirationHandler调用启动后台任务,使您的下载继续运行。

[通常,我用自己的beginBackgroundTaskWithExpirationHandler调用对每个操作进行包装,并在我依次调用endBackgroundTask之前使下一个操作排队,以使队列保持运行。

note单个后台任务的操作时间限制为10分钟,之后iOS会暂停该应用程序。


0
投票

-(void)applicationDidEnterBackground:(UIApplication *)application {

    __block UIBackgroundTaskIdentifier task = [application beginBackgroundTaskWithExpirationHandler:^{
        [application endBackgroundTask:task];
        task = UIBackgroundTaskInvalid;
    }];

}

© www.soinside.com 2019 - 2024. All rights reserved.