I have a subclass of NSURLProtocol, The NSURLConnection works well.
And [NSURLSession sharedSession] works well too.
But, [NSURLSession sessionWithConfiguration:configuration] not work,
I called the [NSURLProtocol registerClass:NSURLProtocolSubclass.class];
what's error?
NSString * stringUrl = @"https://www.apple.com/";
NSURL * url = [NSURL URLWithString:stringUrl];
NSMutableURLRequest * urlRequest = [NSMutableURLRequest requestWithURL:url];
urlRequest.HTTPMethod = @"GET";
NSURLSessionConfiguration * configuration = [NSURLSessionConfiguration ephemeralSessionConfiguration];
configuration.timeoutIntervalForResource = 20.0;
//this can work, but I cann't edit.
//configuration.protocolClasses = @[NSURLProtocolSubclass.class];
//this can work.
NSURLSession * urlSession = [NSURLSession sharedSession];
//this not work.
//NSURLSession * urlSession = [NSURLSession sessionWithConfiguration:configuration];
//Task.
NSURLSessionDataTask * task = [urlSession dataTaskWithRequest:urlRequest completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSHTTPURLResponse * httpUrlResponse = (NSHTTPURLResponse *)response;
NSLog(@"---- session: %ld", (long)httpUrlResponse.statusCode);
}];
[task resume];