![Page 1: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/1.jpg)
These are confidential sessions—please refrain from streaming, blogging, or taking pictures
A session on NSURLSession
Session 705
What’s New inFoundation Networking
Steve AlgernonSenior Wrangler
![Page 2: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/2.jpg)
What’s New in Foundation Networking
•New NSURLSession API■ iOS 7, OS X 10.9■ Out-of-process background transfers
• Framework Enhancements■ NSNetServices■ Single sign-on■ iCloud credential syncing
![Page 3: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/3.jpg)
Foundation Networking
WebKit
Safari
MapKit, etc.
Your App
BSD Networking
Foundation
CoreFoundation / CFNetwork
![Page 4: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/4.jpg)
Foundation Networking
NSNetServices
NSURLConnection
NSStream
CFStream
CFNetServices
CFHTTPReadStream
BSD Networking BSD Sockets
Foundation
CoreFoundation / CFNetwork
![Page 5: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/5.jpg)
Foundation Networking
NSNetServices
NSURLConnection
![Page 6: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/6.jpg)
Foundation Networking
NSURLSession
NSURLConnection
![Page 7: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/7.jpg)
NSURLConnection
• Both a technology and a specific class•Originally written for Safari, available via Foundation
■ WWDC 2003 - Session 418
•URL resolution and loading■ file:// http:// https:// data://■ Extensible via NSURLProtocol
•URL Loading machinery, policies■ Configured via NSURLRequest properties■ Shared Persistent Storage: Cache, Credentials, Cookies
•Authentication and Proxies
![Page 8: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/8.jpg)
NSURLConnection
![Page 9: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/9.jpg)
NSURLConnection
NSURLRequest
![Page 10: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/10.jpg)
NSURLConnection
NSURLRequest
Configuration
![Page 11: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/11.jpg)
NSURLConnection
NSURLConnection
Delegate
NSURLRequest
Configuration
![Page 12: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/12.jpg)
NSURLConnection
GlobalStorageObjects
NSURLConnection
Delegate
NSURLRequest
Configuration
![Page 13: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/13.jpg)
NSURLConnection
GlobalStorageObjects
NSData, NSData…
NSURLConnection
Delegate
NSURLResponse
NSURLRequest
Configuration
![Page 14: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/14.jpg)
NSURLConnection
NSURLConnection
Delegate
<head><title>Meh</title></head><body>
GlobalStorageObjects
HTTP/1.1 200 OK
GET /secret.html HTTP/1.1
cellular: NO
![Page 15: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/15.jpg)
Your Networking Needs
NSURLConnection
GET /secret.html HTTP/1.1
HTTP/1.1 200 OK
<head><title>Meh</title></head><body>
NSURLConnection
Delegate GlobalStorageObjects
![Page 16: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/16.jpg)
Your Networking Needs
NSURLConnection
GET /secret.html HTTP/1.1
HTTP/1.1 200 OK
<head><title>Meh</title></head><body>
NSURLConnection
Delegate GlobalStorageObjects
![Page 17: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/17.jpg)
Your Networking Needs
NSURLConnection
GET /secret.html HTTP/1.1
HTTP/1.1 200 OK
<head><title>Meh</title></head><body>
NSURLConnection
Delegate
Other Framework
GET /secret.html HTTP/1.1
HTTP/1.1 200 OK
<head><title>Meh</title></head><body>
NSURLConnection
DelegateGlobalStorageObjects
![Page 18: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/18.jpg)
NSURLSession
• Both a technology and a specific class• Replaces NSURLConnection
■ Preserves existing concepts and objects■ NSURLRequest, NSURLResponse, etc.
• Configurable Container■ HTTP options■ Subclassable and private storage
• Improved authentication handling■ Connection vs. Request authentication
• Rich delegate model
![Page 19: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/19.jpg)
NSURLSession
•Uploads/Downloads through the filesystem• Encourages separation of Data from Meta-Data
■ NSURLRequst + payload■ NSURLResponse + payload
•Out-of-process Uploads and Downloads■ Uses same delegate model as in-process transfers■ Optimizes battery life■ Supports UIKit multitasking
![Page 20: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/20.jpg)
NSURLSession
![Page 21: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/21.jpg)
NSURLSession
NSURLSession
![Page 22: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/22.jpg)
NSURLSession
NSURLSession
CacheCookiesCreds
Protocols
OptionsConfiguration
![Page 23: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/23.jpg)
NSURLSession
NSURLSession
CacheCookiesCreds
Protocols
OptionsConfiguration
Delegate
![Page 24: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/24.jpg)
NSURLSession
NSURLSession
CacheCookiesCreds
Protocols
OptionsConfiguration
Delegate
HTTP/1.1 200 OK
<head><title>weeble</title></head><body>
GET /foo.html HTTP/1.1
![Page 25: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/25.jpg)
NSURLSession
NSURLSession
CacheCookiesCreds
Protocols
Options
HTTP/1.1 200 OK
<head><title>wobble</title></head><body>
GET /bar.html HTTP/1.1
Configuration
Delegate
HTTP/1.1 200 OK
<head><title>weeble</title></head><body>
GET /foo.html HTTP/1.1
![Page 26: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/26.jpg)
NSURLSession
NSURLSession
CacheCookiesCreds
Protocols
Options
HTTP/1.1 200 OK
<head><title>wobble</title></head><body>
GET /bar.html HTTP/1.1
Configuration
Delegate
HTTP/1.1 200 OK
<head><title>woo</title></head><body>
GET /baz.html HTTP/1.1
HTTP/1.1 200 OK
<head><title>weeble</title></head><body>
GET /foo.html HTTP/1.1
![Page 27: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/27.jpg)
NSURLSession API
•NSURLSessionConfiguration■ Connection/HTTP policies■ Cache, Credentials, Cookie storage
•NSURLSessionTask■ Unit of “work” for a session
•NSURLSessionDelegate•NSURLSession
■ Created with configuration, optional delegate■ Creates one NSURLSessionTask per request■ Long lived object
![Page 28: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/28.jpg)
NSURLSession–Adoption
// NSURLConnection example:id<NSURLConnectionDelegate> myDelegate = [[MyDelegate alloc] init];
for (int i = 0; i < 10; i++) {NSURL* myURL = [NSURL URLWithString:@”http://www.apple.com/”];
NSURLRequest* myRequest = [NSURLRequest requestWithURL:myURL];[myRequest setAllowsCellularAccess:NO];
NSURLConnection* conn;conn = [NSURLConnection connectionWithRequest:myRequest delegate:myDelegate];
}
![Page 29: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/29.jpg)
NSURLSession–Adoption
// NSURLConnection example:id<NSURLConnectionDelegate> myDelegate = [[MyDelegate alloc] init];
for (int i = 0; i < 10; i++) {NSURL* myURL = [NSURL URLWithString:@”http://www.apple.com/”];
NSURLRequest* myRequest = [NSURLRequest requestWithURL:myURL];[myRequest setAllowsCellularAccess:NO];
NSURLConnection* conn;conn = [NSURLConnection connectionWithRequest:myRequest delegate:myDelegate];
}
![Page 30: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/30.jpg)
NSURLSession–Adoption
// NSURLConnection example:id<NSURLConnectionDelegate> myDelegate = [[MyDelegate alloc] init];
for (int i = 0; i < 10; i++) {NSURL* myURL = [NSURL URLWithString:@”http://www.apple.com/”];
NSURLRequest* myRequest = [NSURLRequest requestWithURL:myURL];[myRequest setAllowsCellularAccess:NO];
NSURLConnection* conn;conn = [NSURLConnection connectionWithRequest:myRequest delegate:myDelegate];
}
![Page 31: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/31.jpg)
NSURLSession–Adoption
// NSURLConnection example:id<NSURLConnectionDelegate> myDelegate = [[MyDelegate alloc] init];
for (int i = 0; i < 10; i++) {NSURL* myURL = [NSURL URLWithString:@”http://www.apple.com/”];
NSURLRequest* myRequest = [NSURLRequest requestWithURL:myURL];[myRequest setAllowsCellularAccess:NO];
NSURLConnection* conn;conn = [NSURLConnection connectionWithRequest:myRequest delegate:myDelegate];
}
![Page 32: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/32.jpg)
NSURLSession–Adoption
// NSURLConnection example:id<NSURLConnectionDelegate> myDelegate = [[MyDelegate alloc] init];
for (int i = 0; i < 10; i++) {NSURL* myURL = [NSURL URLWithString:@”http://www.apple.com/”];
NSURLRequest* myRequest = [NSURLRequest requestWithURL:myURL];[myRequest setAllowsCellularAccess:NO];
NSURLConnection* conn;conn = [NSURLConnection connectionWithRequest:myRequest delegate:myDelegate];
}
![Page 33: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/33.jpg)
NSURLSession–Adoption
// NSURLSession example:id<NSURLSessionDelegate> myDelegate = [[MyDelegate alloc] init];
NSURLSessionConfiguration* myConfiguration = [NSURLSession defaultSessionConfiguration];myConfiguration.allowsCellularAccess = NO;
NSURLSession* mySession = [NSURLSession sessionWithConfiguration:myConfiguration delegate:myDelegate delegateQueue:[NSOperationQueue mainQueue];
for (int i = 0; i < 10; i++) {NSURL* myURL = [NSURL URLWithString:@”http://www.apple.com/”];NSURLSessionDataTask* task;task = [mySession dataTaskWithHTTPGetRequest:myURL];
}
![Page 34: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/34.jpg)
NSURLSession–Adoption
// NSURLSession example:id<NSURLSessionDelegate> myDelegate = [[MyDelegate alloc] init];
NSURLSessionConfiguration* myConfiguration = [NSURLSession defaultSessionConfiguration];myConfiguration.allowsCellularAccess = NO;
NSURLSession* mySession = [NSURLSession sessionWithConfiguration:myConfiguration delegate:myDelegate delegateQueue:[NSOperationQueue mainQueue];
for (int i = 0; i < 10; i++) {NSURL* myURL = [NSURL URLWithString:@”http://www.apple.com/”];NSURLSessionDataTask* task;task = [mySession dataTaskWithHTTPGetRequest:myURL];
}
![Page 35: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/35.jpg)
NSURLSession–Adoption
// NSURLSession example:id<NSURLSessionDelegate> myDelegate = [[MyDelegate alloc] init];
NSURLSessionConfiguration* myConfiguration = [NSURLSession defaultSessionConfiguration];myConfiguration.allowsCellularAccess = NO;
NSURLSession* mySession = [NSURLSession sessionWithConfiguration:myConfiguration delegate:myDelegate delegateQueue:[NSOperationQueue mainQueue];
for (int i = 0; i < 10; i++) {NSURL* myURL = [NSURL URLWithString:@”http://www.apple.com/”];NSURLSessionDataTask* task;task = [mySession dataTaskWithHTTPGetRequest:myURL];
}
![Page 36: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/36.jpg)
NSURLSession–Adoption
// NSURLSession example:id<NSURLSessionDelegate> myDelegate = [[MyDelegate alloc] init];
NSURLSessionConfiguration* myConfiguration = [NSURLSession defaultSessionConfiguration];myConfiguration.allowsCellularAccess = NO;
NSURLSession* mySession = [NSURLSession sessionWithConfiguration:myConfiguration delegate:myDelegate delegateQueue:[NSOperationQueue mainQueue];
for (int i = 0; i < 10; i++) {NSURL* myURL = [NSURL URLWithString:@”http://www.apple.com/”];NSURLSessionDataTask* task;task = [mySession dataTaskWithHTTPGetRequest:myURL];
}
![Page 37: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/37.jpg)
NSURLSession–Adoption
// NSURLSession example:id<NSURLSessionDelegate> myDelegate = [[MyDelegate alloc] init];
NSURLSessionConfiguration* myConfiguration = [NSURLSession defaultSessionConfiguration];myConfiguration.allowsCellularAccess = NO;
NSURLSession* mySession = [NSURLSession sessionWithConfiguration:myConfiguration delegate:myDelegate delegateQueue:[NSOperationQueue mainQueue];
for (int i = 0; i < 10; i++) {NSURL* myURL = [NSURL URLWithString:@”http://www.apple.com/”];NSURLSessionDataTask* task;task = [mySession dataTaskWithHTTPGetRequest:myURL];
}
![Page 38: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/38.jpg)
NSURLSession–Adoption
// NSURLSession example:id<NSURLSessionDelegate> myDelegate = [[MyDelegate alloc] init];
NSURLSessionConfiguration* myConfiguration = [NSURLSession defaultSessionConfiguration];myConfiguration.allowsCellularAccess = NO;
NSURLSession* mySession = [NSURLSession sessionWithConfiguration:myConfiguration delegate:myDelegate delegateQueue:[NSOperationQueue mainQueue];
for (int i = 0; i < 10; i++) {NSURL* myURL = [NSURL URLWithString:@”http://www.apple.com/”];NSURLSessionDataTask* task;task = [mySession dataTaskWithHTTPGetRequest:myURL];
}
![Page 39: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/39.jpg)
NSURLSessionConfiguration
• Per-session policies■ Cache, Cookies, Credential stores■ Cell usage, network service type■ Number of connections■ Resource and network timeouts■ TLS protocols■ HTTP proxies, cookies, pipelining, headers■ Protocol handlers
• Storage subclasses• Factory constructors for standard configurations
![Page 40: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/40.jpg)
NSURLSessionConfiguration
•Default for access to global singleton storage, settings:+(NSURLSessionConfiguration*) defaultConfiguration;
• Private storage, in-memory only storage:+(NSURLSessionConfiguration*) ephemeralSessionConfiguration;
•Out-of-process session configuration, keyed to identifier string+(NSURLSessionConfiguration*) backgroundSessionConfiguration:(NSString*) identifier;
• Configuration objects are mutable, but copied when accessed-(NSURLSessionConfiguration*) copy;
![Page 41: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/41.jpg)
NSURLSessionTask
• Replaces NSURLConnection class• Provides status and progress properties• Cancel, Suspend, Resume•Data and Upload tasks provided to differentiate•Download task allows for capturing download state-[NSURLSessionDownloadTask cancelByProducingResumeData:]
•NSURLSessionDelegate methods keyed to task type-URLSession:task:didCompleteWithError:-URLSession:dataTask:didReceiveData:-URLSession:downloadTask:didFinishDownloadingToURL:
![Page 42: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/42.jpg)
NSURLSessionTask
![Page 43: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/43.jpg)
NSURLSessionTask
NSURLSessionTask
![Page 44: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/44.jpg)
NSURLSessionTask
NSURLSessionTask
-cancel-suspend
-resume
![Page 45: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/45.jpg)
NSURLSessionTask
NSURLSessionTask
NSURLSessionDataTask
-cancel-suspend
-resume
![Page 46: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/46.jpg)
NSURLSessionTask
NSURLSessionUploadTask
NSURLSessionTask
NSURLSessionDataTask
-cancel-suspend
-resume
![Page 47: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/47.jpg)
NSURLSessionTask
NSURLSessionUploadTask
NSURLSessionTask
NSURLSessionDataTask
NSURLSessionDownloadTask
-cancelByProducingResumeData
-cancel-suspend
-resume
![Page 48: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/48.jpg)
NSURLSessionDelegate
• Single delegate for all NSURLSession messages■ Session, Task, DataTask, DownloadTask
• Strongly referenced until session invalidated•Delegate messages may block loading
■ Invoke the completion handler to continue
![Page 49: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/49.jpg)
Delegate messages for a sessionNSURLSessionDelegate
-URLSession:didReceiveAuthenticationChallenge:completionHandler:-URLSession:didBecomeInvalidWithError:
• For connection level auth■ NTLM■ Server Trust evaluation■ Client Certificate■ Kerberos implicitly handled
![Page 50: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/50.jpg)
Delegate messages for any taskNSURLSessionTaskDelegate
...task:willPerformHTTPRedirection:newRequest:completionHandler:
...task:didReceiveAuthenticationChallenge:completionHandler:■ Request based challenges■ Basic, Digest, Proxies
...task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend:
...task:needsNewBodyStream:
■ Not needed if uploading from a file:// or NSData■ May be called multiple times
...task:didCompleteWithError:■ Error will be nil for successful requests
![Page 51: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/51.jpg)
Delegate messages for data tasksNSURLSessionDataDelegate
...dataTask:didReceiveResponse:completionHandler:■ Allows you to turn a DataTask into a DownloadTask
...dataTask:didBecomeDownloadTask:■ No more messages for this data task
...dataTask:didReceiveData:■ Incremental data loading
-[NSData enumerateByteRangesUsingBlock:]...dataTask:willCacheResponse:completionHandler:
■ Default is to attempt to cache
![Page 52: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/52.jpg)
Delegate messages for download tasksNSURLSessionDownloadDelegate
...downloadTask:didFinishDownloadingToURL:■ Open or move the file during the callback
...downloadTask:didWriteData:totalBytesWritten:totalBytesExpectedToWrite:
...downloadTask:didResumeAtOffset:expectedTotalBytes:■ Resume offset may be less than previous reported totalBytesWritten
![Page 53: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/53.jpg)
NSURLSession
•Default Session shares NSURLConnection stack[NSURLSession sharedSession].configuration.HTTPCookieStorage == [NSHTTPCookieStorage sharedStorage]
• Custom sessions with private configuration• Invalidation required for your sessions-URLSession:didBecomeInvalidWithError:
• Creates Data, Upload, Download task objects•Asynchronous convenience APIs
■ Can share delegate for auth■ Cancelable
![Page 54: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/54.jpg)
Custom configurationNSURLSession
NSURLSession* mySession = [NSURLSession sessionWithConfiguration:myPrivateSession];NSURL* myPrivateURL = [NSURL URLWithString:@”http://apple.com/secret/”];[mySession dataTaskWithHTTPGetRequest:myPrivateURL completionHandler:^(NSData* data, NSURLResponse* response, NSError* error) { [self gotSecret:data]; }
• Copy or create a configuration• If using the task convenience routines, no delegate required• Private Browsing example:NSURLSessionConfiguration* myConfig = [NSURLSessionConfiguration ephemeralConfiguration];
![Page 55: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/55.jpg)
Custom configurationNSURLSession
NSURLSession* mySession = [NSURLSession sessionWithConfiguration:myPrivateSession];NSURL* myPrivateURL = [NSURL URLWithString:@”http://apple.com/secret/”];[mySession dataTaskWithHTTPGetRequest:myPrivateURL completionHandler:^(NSData* data, NSURLResponse* response, NSError* error) { [self gotSecret:data]; }
• Copy or create a configuration• If using the task convenience routines, no delegate required• Private Browsing example:NSURLSessionConfiguration* myConfig = [NSURLSessionConfiguration ephemeralConfiguration];
![Page 56: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/56.jpg)
Custom configurationNSURLSession
NSURLSession* mySession = [NSURLSession sessionWithConfiguration:myPrivateSession];NSURL* myPrivateURL = [NSURL URLWithString:@”http://apple.com/secret/”];[mySession dataTaskWithHTTPGetRequest:myPrivateURL completionHandler:^(NSData* data, NSURLResponse* response, NSError* error) { [self gotSecret:data]; }
• Copy or create a configuration• If using the task convenience routines, no delegate required• Private Browsing example:NSURLSessionConfiguration* myConfig = [NSURLSessionConfiguration ephemeralConfiguration];
![Page 57: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/57.jpg)
Custom configurationNSURLSession
NSURLSession* mySession = [NSURLSession sessionWithConfiguration:myPrivateSession];NSURL* myPrivateURL = [NSURL URLWithString:@”http://apple.com/secret/”];[mySession dataTaskWithHTTPGetRequest:myPrivateURL completionHandler:^(NSData* data, NSURLResponse* response, NSError* error) { [self gotSecret:data]; }
• Copy or create a configuration• If using the task convenience routines, no delegate required• Private Browsing example:NSURLSessionConfiguration* myConfig = [NSURLSessionConfiguration ephemeralConfiguration];
![Page 58: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/58.jpg)
Custom configurationNSURLSession
NSURLSession* mySession = [NSURLSession sessionWithConfiguration:myPrivateSession];NSURL* myPrivateURL = [NSURL URLWithString:@”http://apple.com/secret/”];[mySession dataTaskWithHTTPGetRequest:myPrivateURL completionHandler:^(NSData* data, NSURLResponse* response, NSError* error) { [self gotSecret:data]; }
• Copy or create a configuration• If using the task convenience routines, no delegate required• Private Browsing example:NSURLSessionConfiguration* myConfig = [NSURLSessionConfiguration ephemeralConfiguration];
![Page 59: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/59.jpg)
Custom configurationNSURLSession
myConfig.allowsCellularAccess = NO;NSURLSession* mySession = [NSURLSession sessionWithConfiguration:myPrivateSession];NSURL* myPrivateURL = [NSURL URLWithString:@”http://apple.com/secret/”];[mySession dataTaskWithHTTPGetRequest:myPrivateURL completionHandler:^(NSData* data, NSURLResponse* response, NSError* error) { [self gotSecret:data]; }
• Copy or create a configuration• If using the task convenience routines, no delegate required• Private Browsing example:NSURLSessionConfiguration* myConfig = [NSURLSessionConfiguration ephemeralConfiguration];
![Page 60: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/60.jpg)
Data Task CreationNSURLSession
•Delegate-based tasks-(NSURLSessionDataTask*) dataTaskWithRequest:(NSURLRequest*) request;-(NSURLSessionDataTask*) dataTaskWithHTTPGetRequest:(NSURL*) url;
•Asynchronous Task Conveniences-(NSURLSessionDataTask*) dataTaskWithRequest:(NSURLRequest*) request completionHandler:(void (^) (NSData* data, NSURLResponse* response, NSError* error) completionHandler;
![Page 61: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/61.jpg)
Upload Task CreationNSURLSession
•Upload tasks-(NSURLSessionUploadTask*) uploadTaskWithRequest:(NSURLRequest*) request fromFile:(NSURL*) file;
-(NSURLSessionUploadTask*) uploadTaskWithRequest:(NSURLRequest*) request fromData:(NSData*) data;
-(NSURLSessionUploadtask*) uploadTaskWithStreamedRequest:(NSURLRequest*) r;
■ Your delegate must implement -needsNewBodyStream:
•Asynchronous Upload Conveniences...:fromFile:completion:^(NSData*, NSURLResponse*, NSError*) completion;...:fromdata:completion:
![Page 62: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/62.jpg)
Download Task CreationNSURLSession
•Download tasks-(NSURLSessionDownloadTask*) downloadTaskWithRequest:(NSURLRequest*) request;-(NSURLSessionDownloadTask*) downloadTaskWithResumeData:(NSData*) data;
•Asynchronous Download Conveniences...downloadTaskWithRequest:completionHandler:^(NSURL* fileURL NSURLResponse* response, NSError* error) completionhandler;...downloadTaskWithResumeData:completionHandler:
• Connection errors produce resume data too[[error userInfo] objectForKey:NSURLSessionDownloadTaskResumeData]
![Page 63: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/63.jpg)
Background TransfersNSURLSession
• Supports upload and download using HTTP(S)• Requires a delegate for event delivery
■ Uses same Upload and Download task delegates as in-process
• Redirections are always taken• -discretionary configuration property
■ Available on iOS, only applies to background transfers■ Optimizes for power and network
![Page 64: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/64.jpg)
Background TransfersNSURLSession
![Page 65: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/65.jpg)
Background TransfersNSURLSession
NSURLSessionIdentifier: “MySession”
![Page 66: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/66.jpg)
Background TransfersNSURLSession
NSURLSessionBackground Daemon
NSURLSessionIdentifier: “MySession”
![Page 67: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/67.jpg)
Background TransfersNSURLSession
NSURLSessionBackground Daemon
NSURLSessionIdentifier: “MySession”
Create Download
![Page 68: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/68.jpg)
Background TransfersNSURLSession
NSURLSessionBackground Daemon
NSURLSessionIdentifier: “MySession”
Progress
Progress
Create Download
![Page 69: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/69.jpg)
NSURLSessionIdentifier: “MySession”
Background TransfersNSURLSession
NSURLSessionBackground Daemon
Progress
Progress
Create Download
![Page 70: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/70.jpg)
Background TransfersNSURLSession
NSURLSessionBackground Daemon
Progress
Progress
Create Download
NSURLSessionIdentifier: “MySession”
![Page 71: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/71.jpg)
NSURLSession
NSURLSessionBackground Daemon
NSURLSessionIdentifier: “MySession”
NSURLSessionIdentifier: “MySession”
Background Transfers
![Page 72: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/72.jpg)
NSURLSession
NSURLSessionBackground Daemon
NSURLSessionIdentifier: “MySession”
NSURLSessionIdentifier: “MySession”
Background Transfers
![Page 73: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/73.jpg)
NSURLSession
NSURLSessionBackground Daemon
Relaunched
NSURLSessionIdentifier: “MySession”
Background Transfers
![Page 74: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/74.jpg)
NSURLSession
NSURLSessionBackground Daemon
Reconnect
Relaunched
NSURLSessionIdentifier: “MySession”
Background Transfers
![Page 75: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/75.jpg)
NSURLSession
NSURLSessionBackground Daemon
Reconnect
Relaunched
Completed
NSURLSessionIdentifier: “MySession”
Background Transfers
![Page 76: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/76.jpg)
Out-of-process TransfersNSURLSession
•Delegate messages received while you’re running• Your app will be launched in the background…
■ to service auth requests■ when all tasks complete
• Creating a session from same identifier “reconnects" you to existing background session
-(void) getTasksWithCompletionHandler:^(NSArray* dataTasks, NSArray* uploadTasks, NSArray* downloadTasks) completion;
![Page 77: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/77.jpg)
DemoNSURLSession - Background Requests
Dan VinegradSoftware Engineer
![Page 78: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/78.jpg)
NSURLSession vs. NSURLConnection
• Connection based auth schemes•HTTP configuration options• Private, subclassable storage• Background, out-of-process transfers•API baseline
![Page 79: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/79.jpg)
What’s New in Foundation Networking
•New NSURLSession API■ iOS 7, OS X 10.9■ Out-of-process background transfers
• Framework Enhancements■ NSNetServices■ Single sign-on■ iCloud credential syncing
![Page 80: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/80.jpg)
NSNetServices
• Browse for and connect to Bonjour services-(BOOL) getInputStream:(NSInputStream**) inputStreamPtr outputStream:(NSOutputStream**) outputStreamPtr;
•New property: includesPeerToPeer■ Browsing and publishing on Peer to Peer Wi-Fi and Bluetooth■ Peer to Peer Wi-Fi new in iOS 7
![Page 81: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/81.jpg)
NSNetServices
•New option: NSNetServiceListenForConnections-(void) [NSNetService publishWithOptions:(NSNetServiceOptions) options
• Binds IPv4 and IPv6 listening sockets• Invokes delegate on incoming connections:-(void) netService:(NSNetService*) service didAcceptConnectionWithInputStream:(NSInputStream*) is outputStream:(NSOutputStream*) os;
![Page 82: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/82.jpg)
Single sign-onAuthentication
• Kerberos Authentication•Available in MDM environments•Device Managers specify:
■ Applicable URLs■ Applications
• Kerberos authentication challenges are handled by the system• See “Extending Your Apps for Enterprise and Education Use” session
![Page 83: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/83.jpg)
iCloud Credential Syncing
• Credentials synced between devices through iCloud• Credential persistence option:NSURLCredentialPersistenceSynchronizable
• Credential storage API:-(void) removeCredential:(NSURLCredential*) credential forProtectionSpace:(NSURLProtectionSpace*) protectionSpace options:(NSDictionary*) options;
Key: NSURLCredentialStorageRemoveSynchronizableCredentialsRemoves a credential across all participating devices
![Page 84: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/84.jpg)
Summary
•NSURLSession■ New API for iOS 7.0 and OS X 10.9■ Replaces NSURLConnection■ Extensive Customization■ Out-of-process background transfers
![Page 85: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/85.jpg)
Summary
•NSNetServices■ Peer to Peer support■ Server creation
•NSURLAuthentication■ Kerberos single sign-on■ iCloud credential syncing
![Page 86: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/86.jpg)
More Information
Paul DanboldCore OS Technologies [email protected]
DocumentationFoundation Class Referencehttp://developer.apple.com/
Apple Developer Forumshttp://devforums.apple.com
![Page 87: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/87.jpg)
What’s New in State Restoration MissionThursday 3:15PM
What’s New with Multitasking PresidioTuesday 2:00PM
Nearby Networking with Multipeer Connectivity MissionWednesday 10:15AM
Extending Your Apps for Enterprise and Education Use Nob HillTuesday 3:15PM
Related Sessions
Managing Apple Devices Pacific HeightsTuesday 11:30AM
![Page 88: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/88.jpg)
Labs
Multipeer Connectivity Lab Core OS Lab AWednesday 11:30AM
Foundation Networking Lab Core OS Lab BWednesday 10:15AM
Cocoa and Foundation Lab Frameworks Lab AWednesday 11:30AM
Multipeer Connectivity Lab Core OS Lab BFriday 9:00AM
Multitasking Lab Services Lab BThursday 9:00AM
Networking Lab Core OS Lab AThursday 9:00AM
![Page 89: What’s New in Foundation Networking€¦ · What’s New in Foundation Networking •New NSURLSession API iOS 7, OS X 10.9 Out-of-process background transfers •Framework Enhancements](https://reader034.vdocuments.site/reader034/viewer/2022050517/5fa191d4dae4663e3d624db1/html5/thumbnails/89.jpg)