来自 NSURLSession.h ...
/* An optional array of Class objects which subclass NSURLProtocol.
The Class will be sent +canInitWithRequest: when determining if
an instance of the class can be used for a given URL scheme.
You should not use +[NSURLProtocol registerClass:], as that
method will register your class with the default session rather
than with an instance of NSURLSession.
Custom NSURLProtocol subclasses are not available to background
sessions.
*/
@property (nullable, copy) NSArray<Class> *protocolClasses;
自定义NSURLProtocol子类不适用于后台 会话。
将自定义NSURLProtocol子类限制为仅在前台会话中触发会有什么好处?
答案 0 :(得分:1)
来自Apple文档:
后台会话与默认会话类似,只是一个单独的进程处理所有数据传输。
Apple根本没有提供将NSURLProtocol
子类注入另一个由iOS本身管理的进程的方法。
同样的限制适用于WKWebView
。