Hi guys,
thank for your effort for contributing such a convenient Networking API.
We used it and feel friendly.
But there is a weird behavior when we implement background uploading task.
we can not continue upload second item to server if we do
--------> [manager invalidateSessionCancelingTasks:YES];
below is fragment codes, and note that our sessionManager not get singleton
- (AFURLSessionManager *)sessionManager
{
AFURLSessionManager *manager = nil;
NSString *identifierName = [NSString stringWithFormat:@"ID-Upload-Session%d", serialNumber];
NSURLSessionConfiguration *configuration =
[NSURLSessionConfiguration backgroundSessionConfiguration:identifierName];
manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
[manager setAttemptsToRecreateUploadTasksForBackgroundSessions:YES];
serialNumber++;
return manager;
}
- (id) uploadFile:(NSString *)uploadUrl fileURL:(NSURL *)fileURL
{
NSProgress *progress = nil;
AFURLSessionManager *manager = [self sessionManager];
NSURLSessionUploadTask *uploadTask =
[manager uploadTaskWithRequest:request
fromFile:fileURL
progress:&progress
completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
NSLog(@"response: %@", response);
[lock lock];
[lock unlockWithCondition:FINISHED];
}];
[progress addObserver:self forKeyPath:@"fractionCompleted" options:NSKeyValueObservingOptionNew context:NULL];
[uploadTask resume];
[lock lockWhenCondition:FINISHED];
[lock unlock];
// TODO: This line makes the auto-upload cannot continue due to unknown reason. Per the official document, it needs to invalidate session to avoid memory leak. Have to study how to invalidate it properly.
//[manager invalidateSessionCancelingTasks:YES];
}
@dogtim There are a number of mistakes in the code posted, which suggest some fundamental misunderstandings about how AFNetworking and asynchronous programming work. GitHub Issues is for reporting bugs in the framework and discussing features, so this is not an appropriate forum to discuss this. I would recommend taking a look at the code in the included example project, and reading Apple's Concurrency Programming Guide and Foundation URL Loading System Programming Guide.
I cannot believe how many issues you can close this way not helping anybody... Maybe you can just point people to developer.apple.com , so they know where to start ...
Most helpful comment
I cannot believe how many issues you can close this way not helping anybody... Maybe you can just point people to developer.apple.com , so they know where to start ...