当我尝试使用以这种方式创建的后台会话提交下载URL时:
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;
}
该应用程序崩溃:
CFNetwork SSLHandshake失败(-9810)
当我提交相关任务时:
let url=NSURL(fileURLWithPath: escapedUrlString!);
let task = backgroundSession()?.downloadTaskWithURL(url!, completionHandler: {[weak self](data, reponse, error) in
//UIApplication.sharedApplication().applicationIconBadgeNumber = 3;
})
task!.resume()
如果我通过使用以下创建的标准会话执行相同的操作:
NSURLSession.sharedSession()
连接没有问题,但当应用程序变为非活动状态时,当然会停止提交。
错误的基础可能是什么问题?
答案 0 :(得分:-2)
我丢失了对此主题的引用,但问题以某种方式得到了解决。