Answer the question
In order to leave comments, you need to log in
How to resume file uploads in NSURLSession after application restart?
I create several downloadTasks and then kill the application.
I launch the application and get an array with unfinished tasks, after which I resume loading all in a loop.
But the files never show up in the documents folder. (if you don't reload applications, the download itself works)
I'm using AFNetworking 2.0.2
The full code for this project is github.com/nullproduction/FileDownloader
//
// DownloadsViewController.m
//
#import "DownloadsViewController.h"
@implementation DownloadsViewController
- (id)init
{
[self printDocumentsPath];
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration backgroundSessionConfiguration:@"downloads"];
manager = ;
return [documentsDirectoryPath URLByAppendingPathComponent:[targetPath lastPathComponent]];
} completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) {
NSLog(@"File downloaded to: %@", filePath);
}];
[downloadTask resume];
NSLog(@"%d", downloadTask.taskIdentifier);
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"addDownloadTask" style:UIBarButtonItemStyleBordered target:self action:@selector(addDownloadTask:)];
}
- (void)printDocumentsPath
{
NSString *documentsDirectoryPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
NSLog(@"%@", documentsDirectoryPath);
}
@end
Answer the question
In order to leave comments, you need to log in
Try to resume operations
In AppDelegate.m
To pause operations
- (void)applicationDidEnterBackground:(UIApplication *)application
- (void)applicationWillEnterForeground:(UIApplication *)application
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question