1

In wwdc viedo [[networking with nsurlsession]], they say NSURLSession supports HTTP/2 protocol automatically;

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.

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

Anybody who knows why?

1 Answers1

0

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.

dgatwood
  • 10,129
  • 1
  • 28
  • 49