我有以下代码上传文件:
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];
第二次加载时,出现以下错误:
标识符为<的后台URLSession ID>已经存在!
如何重复使用URLSession
?