I am using URL background session for pdf uploading as data stream, using ios version > 9.0. I am setting timeout interval of 300 sec. Its not working at all. After 10 seconds it gets timeout error.
Piece of code is given below
NSTimeInterval reqTimeInterval = 300.0f;
- (NSURLSession *)uploadSessionForMrNo:(NSString *)mrNo
userRoleId:(NSString *)userRoleId
timestamp:(NSString *)timestamp {
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
queue.maxConcurrentOperationCount = 4;
NSString *backgroundSessionIdentifier = [NSString stringWithFormat:@"backgroundPdfUploadIdentifier_%@",mrNo];
NSURLSessionConfiguration *backgroundSession = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:backgroundSessionIdentifier];
backgroundSession.discretionary = true;
NSURLSession *session = [NSURLSession sessionWithConfiguration:backgroundSession delegate:self delegateQueue:queue];
[session setAccessibilityLabel:mrNo];
[session setAccessibilityValue:userRoleId];
[session setAccessibilityHint:timestamp];
return session;
}
- (void)uploadPdfRequest:(NSURLRequest *)request
forMrNo:(NSString *)mrNo
userRoleId:(NSString *)userRoleId
andTimestamp:(NSString *)timestamp {
NSURLSession *session = [self uploadSessionForMrNo:mrNo userRoleId:userRoleId timestamp:timestamp];
NSURLSessionDataTask *postDataTask = [session dataTaskWithRequest:request];
NSLog(@"postDataTask %@ timeout %f",postDataTask,request.timeoutInterval);
[postDataTask resume];
}
Request to upload data stream.
NSMutableURLRequest *request = [[NSURLRequest requestForPDFStringUpload:uploadQueue.uploadData] mutableCopy];
[request setValue:[DataExchange authToken] forHTTPHeaderField:FBENCRYPT_TOKEN_KEY];
[request setCachePolicy:NSURLRequestUseProtocolCachePolicy];
[request setTimeoutInterval:reqTimeInterval];
[self uploadPdfRequest:request forMrNo:uploadQueue.mrNo userRoleId:uploadQueue.userRoleId andTimestamp:uploadQueue.timestamp];
delegate
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task
didCompleteWithError:(NSError *)error {
if (error) {
// Handle error
NSLog(@"Error %@",error);
}
[session finishTasksAndInvalidate];
self.receivedData = nil;
}
If internet is working fine then its fine otherwise After 10 seconds I get
Error Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." UserInfo={NSErrorFailingURLStringKey=http://test.mydomain.com/common.svc/json/FileUploadPDF, NSErrorFailingURLKey=http://test.mydomain.com/common.svc/json/FileUploadPDF, _kCFStreamErrorDomainKey=4, _kCFStreamErrorCodeKey=-2104, NSLocalizedDescription=The request timed out.}
More detail about this issue,
As I have checked my code in ios 9.3 simulator, it waits for connectivity to appear. Then continues to uploading. I have checked it by 4 minutes of waiting it works. But when I run this code to ios 11.0.1 it gets timeout after 10 seconds. What should I need to do extra to achieve it. I have also tried
if ([backgroundSession respondsToSelector:@selector(setWaitsForConnectivity:)]) {
[backgroundSession setWaitsForConnectivity:true];
}
but it has no effect.
You can use demo file below:-
session.timeoutIntervalForRequest = 30.0; session.timeoutIntervalForResource = 60.0;
– Mahaliarefer this link i hope it should help you
@ Warewolf – Warlock