[NSURLSession sharedSession] protocols can't be unregistered. NSURLConnection worked fine with it.

Originator:justf4st
Number:rdar://30325261 Date Originated:02-Feb-2017
Status:Open Resolved:
Product:iOS Product Version:
Classification:NSURL Reproducible:
 
Area:
CFNetwork Framework

Summary:
We used NSURLConnection in our app and tried to migrate it to NSURLSession.
We are unable to unregister our protocol from sharedSession, so it's always called even after unregister command. We want to use another protocol in several cases. We tried to use sessionWithConfiguration, but it's not called with webView, so sessionWithConfiguration doesn't fit our needs.

Steps to Reproduce:
Precondition:
[NSURLProtocol registerClass:[FirstCustomProtocol class]];
Get shared session [NSURLSession sharedSession]. 
Execute one request (with custom protocol scheme) with sessionTask from this session.
The FirstCustomProtocol should be be asked
+ (BOOL)canInitWithRequest:(NSURLRequest *)request.


Steps:
Call [NSURLProtocol unregisterClass:[FirstCustomProtocol class]]; to unregister protocol (same way as unregistered protocols in NSURLConnection).





Expected Results:
Custom protocol class should not be called, because we unregistered it.

Actual Results:
The custom protocol is still called +canInitWithRequest:.

Version:
iOS 8.4.1, iOS 9.0.2, iOS 10.2, 10.3 beta

Notes:


Configuration:
Any device

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!