0

我有以下代码来上传文件:

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];

在第二次加载时,出现以下错误:

标识符为 <ID> 的后台 URLSession 已经存在!

我如何重复使用URLSession?

4

0 回答 0