0

I have the following code to upload a file:

self.uploadManager = [[AFURLSessionManager alloc] initWithSessionConfiguration:lSessionConfiguration];
self.uploadManager.responseSerializer = [AFHTTPResponseSerializer serializer];
NSMutableURLRequest *req = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:uploadURL]];
[req setHTTPMethod:@"POST"];
NSProgress *progress;
[[self.uploadManager uploadTaskWithRequest:req fromFile:fileURL progress:&progress completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
    NSAssert(!error, @"%s: uploadTaskWithRequest error: %@", __FUNCTION__, error);
    NSLog(@"Task Completed: %@ %@", response, [responseObject class]);



    UILocalNotification *notif = [[UILocalNotification alloc] init];
    //notif.fireDate = [NSDate dateWithTimeIntervalSinceNow:1];
    notif.alertBody = @"Upload Complete";
    notif.timeZone = [NSTimeZone defaultTimeZone];
    [[UIApplication sharedApplication] scheduleLocalNotification:notif];
}] resume];

[progress addObserver:self
           forKeyPath:@"fractionCompleted"
              options:NSKeyValueObservingOptionNew
              context:NULL];

On second load, the following error appears:

A background URLSession with identifier < ID > already exists!

How do I re-use the URLSession ?

Raptor
  • 53,206
  • 45
  • 230
  • 366
  • Please check this link it help will help you (1) http://stackoverflow.com/questions/26453822/using-afnetworking-2-0-with-background-tasks (2)http://stackoverflow.com/questions/21350125/afnetworking-2-0-and-background-transfers/21359684#21359684 – Harish May 04 '15 at 11:46
  • both questions are similar, but does not make use of `uploadTaskWithRequest`... – Raptor May 04 '15 at 15:44

0 Answers0