2

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 子类限制为仅在前台会话中触发有什么好处?

4

1 回答 1

1

来自 Apple 文档:

后台会话类似于默认会话,不同之处在于一个单独的进程处理所有数据传输。

Apple 根本没有提供将您的NSURLProtocol子类注入另一个由 iOS 本身管理的进程的方法。

同样的限制适用于WKWebView

于 2016-03-04T16:07:11.687 回答