mesmerizingr mesmerizingr - 4 months ago 41
iOS Question

Creating multiple NSURLSession objects in case of HTTPS host

I'd like to know is it good to create multiple

NSURLSession
objects when connecting to HTTPS host? The reason I'm asking this is because I should evaluate a server certificate during an initial TLS handshake (the server accepts clients without certificates) and the place I'm going to do that is
NSURLSessionDelegate
's
URLSession:didReceiveChallenge:completionHandler:
.

But that means I should create some base class that implements this method and derive all future delegates from it when using them for other means like
URLSession:downloadTask:didWriteData:totalBytesWritten:totalBytesExpectedToWrite:
.

Also it creates concerns that
URLSession:didReceiveChallenge:completionHandler:
would be called for every
NSURLSession
I make creating an additional overhead. As for HTTP/1.1
Connection: keep-alive
should be a default behaviour and (ideally) newly-created
NSURLSession
should be using connections from some connection pool.

Answer

I've found the answer to my question in this Technical Q&A:

Since NSURLSession maintains it's own TLS session cache...

So I guess it's better to keep one NSURLSession if one doesn't want to TLS-handshake every time it performs a connection.