来自 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;
Custom NSURLProtocol subclasses are not available to background sessions.
将自定义 NSURLProtocol 子类限制为仅在前台 session 中触发有什么好处?
来自 Apple 文档:
Background sessions are similar to default sessions, except that a separate process handles all data transfers.
Apple 根本不提供将您的 NSURLProtocol
子类注入(inject)到另一个由 iOS 本身管理的进程的方法。
同样的限制适用于 WKWebView
。
关于ios - 自定义 NSURLProtocol 子类对后台 session 不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34865414/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |