恢复使用NSURLSession任务时,应用程序从背景或重启设备拆除 [英] Resuming tasks using NSURLSession when app removed from background or on device reboot

查看:195
本文介绍了恢复使用NSURLSession任务时,应用程序从背景或重启设备拆除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经检查了很多文档,但无法发现的恢复使用NSURLSession :当应用程序从背景上或者设备重启删除任务的解决方案。

I have checked many docs but could not found solution for Resuming tasks using NSURLSession when app removed from background or on device reboot.

我处理的亚马逊S3上传一些文件,在该我能够

I am dealing with amazon S3 to upload some files, In that I am able to

  1. 上传使用NSURLSessionUploadTask文件S3,当应用程序是在前台和后台。
  2. 恢复任务:当应用程序的应声由于其他原因而上传,如果应用程序是不是从后台删除。
  3. 重新启动任务如果我的重启设备上传时,如果应用程序是不是从后台删除。
  1. Upload file to S3 using NSURLSessionUploadTask, when app is in foreground as well as in background.
  2. Resume task when app crashed due to any other reason while uploading and if app is not removed from background.
  3. Restart task if I reboot device while uploading and if app is not removed from background.

下面是我的code才达到的简历fuctionality写成的appdelegate的applicationDidBecomeActive方法。

Here is my code to achive resume fuctionality written in applicationDidBecomeActive method of appdelegate.

// Initialize session config and the background session
NSURLSession *l_taskSession = [self backgroundSession];

[l_taskSession getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks)
 {
     if([uploadTasks count])
     {
         for (int i=0; i<[uploadTasks count]; i++)
         {
             NSURLSessionUploadTask *uploadRequestTask = (NSURLSessionUploadTask*)[uploadTasks objectAtIndex:i];
             [uploadRequestTask  resume];
             NSLog(@"-------- Upload Resumed ------- ");
         }
     }
     else if(![uploadTasks count])
     {
         NSLog(@"------- There are no previous tasks -------");
     }
 }];

现在的问题是在这两个案例(2及3)上述不给那名在进步,当我删除从后台应用程序的任务列表,并推出了一遍,按code它属于在否则,如果条件和日志

Now the problem is in both the case (2 & 3) mentioned above it doesn't give list of tasks that were in progress, when I removed app from background and launched again, as per code it falls in else if condition and logs

2015年6月12日17:12:32.902 AppName的[162:60B] -------没有previous任务-------

2015-06-12 17:12:32.902 AppName[162:60b] ------- There are no previous tasks -------

所以,我的问题这可能恢复任务时,从应用程序中删除的背景?或者,任何人可以只给我参考链接在哪里可以找到答案相同的,任何帮助是AP preciated。

So my question is this possible to resume tasks when app removed from background ? Or can anybody just give me reference links where I can find answer for the same, any help is appreciated.

推荐答案

最后,我得出的结论是,

Finally I come to conclusion that,

如果iOS应用程序是由系统终止和重新启动,应用程序可以使用相同的标识符来创建一个新的配置对象和会话和检索的转让正在进行中,在终止时的状态。 此行为仅适用于正常终止的系统应用程序的。

If an iOS app is terminated by the system and relaunched, the app can use the same identifier to create a new configuration object and session and retrieve the status of transfers that were in progress at the time of termination. This behavior applies only for normal termination of the app by the system.

如果用户终止从多任务屏幕上的应用程序,该系统将取消所有会话的背景转移。

有关详细信息检查苹果的NSURLSessionConfiguration类参考<一个文档href="https://developer.apple.com/library/mac/documentation/Foundation/Reference/NSURLSessionConfiguration_class/#//apple_ref/occ/clm/NSURLSessionConfiguration/backgroundSessionConfigurationWithIdentifier:"相对=nofollow>这里。

For more details check Apple's documentation on NSURLSessionConfiguration Class Reference here.

这篇关于恢复使用NSURLSession任务时,应用程序从背景或重启设备拆除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆