应用程序关闭时在后台运行任务

问题描述

| 我正在创建一个应用程序,其中我使用保管箱sdk从保管箱下载大文件。下载功能的工作方式是我调用downloadFile方法并将其传递给委托,该委托将在文件开始下载时以及文件完全下载后回叫。 但是,现在,如果正在下载文件并且我关闭了该应用程序,则文件下载将暂停,直到用户返回该应用程序为止。 我尝试使用以下代码,但是当我关闭应用程序时,下载仍然无法完成,直到您返回应用程序。
UIApplication* app = [UIApplication sharedApplication];

bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
    [app endBackgroundTask:bgTask];
    bgTask = UIBackgroundTaskInvalid;
}];

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0),^{


     //This call calls the sdk to start downloading the file. That method will then
     // call this classes delegate methods with the progress of the download as well
     // as when the file is totally finished downloading
     [DBUtils downloadFile:fileVO.filename withHash:fileVO.filehash withRestClient:self.restClient];


    [app endBackgroundTask:bgTask];
    bgTask = UIBackgroundTaskInvalid;
});
知道我该如何解决这个问题?     

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)