How to programmatically add a proxy to an NSURLSession

It turns out, the dictionary keys you want are the Stream variants, they are the ones that resolve down to “HTTPProxy” and such: NSString* proxyHost = @”myProxyHost.com”; NSNumber* proxyPort = [NSNumber numberWithInt: 12345]; // Create an NSURLSessionConfiguration that uses the proxy NSDictionary *proxyDict = @{ @”HTTPEnable” : [NSNumber numberWithInt:1], (NSString *)kCFStreamPropertyHTTPProxyHost : proxyHost, (NSString *)kCFStreamPropertyHTTPProxyPort … Read more

Showing the file download progress with NSURLSessionDataTask

You need to implement following delegates: <NSURLSessionDataDelegate, NSURLSessionDelegate, NSURLSessionTaskDelegate> Also need to create two properties: @property (nonatomic, retain) NSMutableData *dataToDownload; @property (nonatomic) float downloadSize; – (void)viewDidLoad { [super viewDidLoad]; NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration]; NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate: self delegateQueue: [NSOperationQueue mainQueue]]; NSURL *url = [NSURL URLWithString: @”your url”]; NSURLSessionDataTask *dataTask = … Read more

NSURLSession concurrent requests with Alamofire

Yes, this is expected behavior. One solution is to wrap your requests in custom, asynchronous NSOperation subclass, and then use the maxConcurrentOperationCount of the operation queue to control the number of concurrent requests rather than the HTTPMaximumConnectionsPerHost parameter. The original AFNetworking did a wonderful job wrapping the requests in operations, which made this trivial. But … Read more