URLSessionConfiguration
Undocumented
-
Called on a session configuration before it’s used to instantiate an NSURLSession instance.
This should ONLY be called if the configuration is NOT the defaultSessionConfiguration.
Swift3:
let configuration = URLSessionConfiguration.ephemeral configuration.addCaffeine() let session = URLSession(configuration: configuration) let request = URLRequest(URL: NSURL(string: "http://google.com")!) _ = session.dataTask(with: request) { (data, res, err) -> Void in print("I used Caffeine to get here") }.resume()
Swift 2.3:
let configuration = NSURLSessionConfiguration.ephemeralSessionConfiguration() configuration.addCaffeine() let session = NSURLSession(configuration: configuration) let request = NSMutableURLRequest(URL: NSURL(string: "http://google.com")!) session.dataTaskWithRequest(request) { (data, res, err) -> Void in print("I used Caffeine to get here") }.resume()
Objective-C:
NSURLSessionConfiguration *config = [NSURLSessionConfiguration ephemeralSessionConfiguration]; [config addCaffeine]; NSURLSession *session = [NSURLSession sessionWithConfiguration:config]; [session dataTaskWithURL:[NSURL URLWithString:@"http://google.com"] completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { NSLog(@"I used Caffeine to get here"); }];
Warning
The URL will NOT be Caffeinated unless it is also allowed using CaffeineHTTPProxy’sallow:
See also
allow:
Declaration
Swift
public final func addCaffeine()