简体   繁体   English

iOS9 NSURLSession HTTP / 2

[英]iOS9 NSURLSession HTTP/2

In wwdc viedo [[networking with nsurlsession]], they say NSURLSession supports HTTP/2 protocol automatically; 在wwdc viedo [[与nsurlsession联网]]中,他们说NSURLSession自动支持HTTP / 2协议。

but when i use this code, 但是当我使用这段代码时

 let sessionConfig = NSURLSessionConfiguration.defaultSessionConfiguration()
 let session = NSURLSession(configuration: sessionConfig)
 let url = NSURL(string: "https://www.google.com.hk")
 let task = session.dataTaskWithURL(url) {
     (data: NSData?, response: NSURLResponse?, error: NSError?) in
     ...
 }
 task?.resume()

it does not use HTTP/2. 它不使用HTTP / 2。

But with this code ,it's just ok 但是有了这段代码,就可以了

let session = NSURLSession.sharedSession() 
let url = NSURL(string: "https://www.google.com.hk")
let task = session.dataTaskWithURL(url) {
     (data: NSData?, response: NSURLResponse?, error: NSError?) in
    ...
}
task?.resume() 

The network is ok, it uses http/2 网络还可以,它使用http / 2

Anybody who knows why? 谁知道为什么?

File a bug. 提交错误。 A session created with the default session configuration should behave just like the shared session does. 使用默认会话配置创建的会话的行为应与共享会话相同。

I'm assuming, of course, that the code around that snippet maintains a strong reference to the session, and that you're not seeing some weird edge case bug where the session goes away and its configuration becomes nil before the task finishes or something. 当然,我假设该代码段周围的代码对会话保持了强大的引用,并且您没有看到一些奇怪的边缘错误,该错误会导致会话消失并且在任务完成之前它的配置变为零。 。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM