2

I am using the following code to upload image using NSURLSessionUploadTask

NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];

NSURL *URL = [NSURL URLWithString:@"http://example.com/upload"];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];

NSURL *filePath = [NSURL fileURLWithPath:@"file://path/to/image.png"];
NSURLSessionUploadTask *uploadTask = [manager uploadTaskWithRequest:request fromFile:filePath progress:nil completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
    if (error) {
        NSLog(@"Error: %@", error);
    } else {
        NSLog(@"Success: %@ %@", response, responseObject);
    }
}];
[uploadTask resume];

My file gets uploaded on server properly, but if the app is killed in between the upload is in progress then i am unable to restore the state of my upload by getting session identifier and then after resume it.

After googling out I found that the below delegate method will be called (after the relaunch of my app) if my upload is interrupted, but this method doesn't seems to be called in my case.

- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task
                           didCompleteWithError:(nullable NSError *)error;

Am I using the correct method to identify session identifier or there is some other method to implement my requirement?

Rahul Mathur
  • 862
  • 1
  • 7
  • 20

0 Answers0