When I try to submit a download URL by using a background session created in this way:
func backgroundSession() -> NSURLSession?{
var session:NSURLSession?;
var configuration:NSURLSessionConfiguration!;
if NSURLSessionConfiguration.respondsToSelector(Selector("backgroundSessionConfigurationWithIdentifier:")){
configuration = NSURLSessionConfiguration.backgroundSessionConfigurationWithIdentifier("myBackgroundSessionIdentifier\(++counter)")
}
else{
configuration = NSURLSessionConfiguration.backgroundSessionConfiguration("myBackgroundSessionIdentifier\(++counter)")
}
configuration.allowsCellularAccess = true;
configuration.timeoutIntervalForRequest = 20.0;
configuration.timeoutIntervalForResource = 40.0;
configuration.HTTPMaximumConnectionsPerHost = 1;
configuration.networkServiceType = .NetworkServiceTypeBackground;
configuration.discretionary = false;
let queue=NSOperationQueue.mainQueue()
session = NSURLSession(configuration:configuration, delegate:self, delegateQueue:queue)
return session;
}
The app crashes with:
CFNetwork SSLHandshake failed (-9810)
when I submit the relative task with:
let url=NSURL(fileURLWithPath: escapedUrlString!);
let task = backgroundSession()?.downloadTaskWithURL(url!, completionHandler: {[weak self](data, reponse, error) in
//UIApplication.sharedApplication().applicationIconBadgeNumber = 3;
})
task!.resume()
While if I do the same by using a standard session created with:
NSURLSession.sharedSession()
the connection goes without problems, but of course stops being submitted when the app becomes inactive.
What might be the problem at the base of the error?
I lost the reference to this thread, but the problem got resolved in some way.