NSURLSession didCompleteWithError:gets called with NSError is nil
Asked Answered
H

1

4

Scenario is taking the app to background and foreground multiple times when its uploading is in progress,didCompleteWithError: method is called while taking app to foreground with error parameter is null. Probabilty is 1/3.

How do i find out what went wrong as error parameter does not give anything.

Hellenism answered 7/7, 2015 at 7:40 Comment(5)
I guess this can give you any hint:- https://mcmap.net/q/1710108/-when-does-nsurlsession-runMusetta
it didn't help.Is there any other way to get what causes nil error simultaneously not completing with successHellenism
HI Vani, did you resolved this issue?Robby
not able to resolve and update here if you could find any solution.Hellenism
@Vani. Try to check - URLSession:didBecomeInvalidWithError: by implementing NURLSession delegate:developer.apple.com/library/ios/documentation/Foundation/…:Omophagia
O
3

The problem is that didCompleteWithError report only client side error, otherwise is nil. iOS doc said:

"Server errors are not reported through the error parameter. The only errors your delegate receives through the error parameter are client-side errors, such as being unable to resolve the hostname or connect to the host."

This is the link to the documentation.

If you want to check session's errors you have to implement session protocol delegate

- URLSession:didBecomeInvalidWithError:

Remember to invalidate the session after stop using it. So if you create an NSURLSession like this:

NSURLSessionConfiguration *backgroundConfigurationObject = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:@"applycasession"];
    self.backgroundSession = [NSURLSession sessionWithConfiguration:backgroundConfigurationObject delegate:self delegateQueue:[NSOperationQueue mainQueue]];

When you finish to use it you have to call:

 [self.backgroundSession invalidateAndCancel];

Please read the documents about "Life Cycle of URL Session" at this link

Omophagia answered 15/5, 2016 at 15:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.