I am using the following code to upload a file on my server. The file starts uploading but then i disconnect my iphone device from my wifi. I do not see any errors returning...the connection keep staying alive. I waited for more than 10 minutes! completionHandler: does not trigger. I even tried setting the timeoutinterval in NSMutableURLRequest *request and AFURLSessionManager *manager to 10 seconds but no luck. Even tried reachability class inside the upload procedure but no luck. What am i missing?
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:ccId];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:preSignedURL];
request.HTTPMethod = @"PUT";
[request setValue:@"video/mp4" forHTTPHeaderField:@"Content-Type"];
NSString* filePath = [self getFilePathForFileName:@"video.mp4" video:videoURL];
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath:filePath]){
return;
}
NSURLSessionUploadTask *uploadTask = [manager uploadTaskWithRequest:request fromFile:[[NSURL alloc] initFileURLWithPath:filePath] progress:^(NSProgress * _Nonnull uploadProgress) {
NSLog(@"Upload in progress...");
}
completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) {
NSFileManager *fileManager = [NSFileManager new];
[fileManager removeItemAtPath:filePath error:NULL];
if (error) {
NSLog(@"Error occured on video upload test: %@ for %@", error,ccId);
completion(nil);
}
else{
NSLog(@"%@ %@", response, responseObject);
completion(response);
}
}];
[uploadTask resume];