WWDC 2015

Networking with NSURLSession

Networking is one of critical features for every iOS app.In iOS 9, there are some important update for networkings and related framework NSURLSession

App Transport Security (ATS)

  • Disallow cleartext HTTP URL locals
  • Encourage secure connections
  • Defaults to stronger security
  • Allows exception via app's info.plist

Sample info.plist for exception http protocol

More explanation and keys on ATS

ATS only active when the app is built with iOS 9 SDK for iOS 9 and OX El Capitan

Automatic convert from http:// to https://

Use NSAllowsArbitraryLoads for quick triage (allow load all http and https)

CFNETWORK_DIAGNOSTICS=1 to log all error from system networking

NSURLSession supports HTTP/2 automatically and nothing to change in code

NSURLSession on watchOS

NSURLSession availabe in watchOS 2

Best Practices

Download the minimal assets

  • small screen
  • limited bandwidth

Since the apps run very short time

  • send small amounts of data
  • use background upload and downloads for larger content

NSURLConnection is deprecated in OS 10.11 and iOS 9.0

  • existing apps using it will still work
  • New features only available in NSURLSession
  • Not supported on watchOS

New features on NSURLSession

  • shared cookies storage
  • NSURLSessionStreamTask
    • supports TCP/IP connections with hostnames and ports
    • NSURLSession configuration and session delegates applies
    • support TLS
    • convertion from NSStream