Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 自定义NSURLProtocol子类对后台会话不可用_Ios_Nsurlprotocol - Fatal编程技术网

Ios 自定义NSURLProtocol子类对后台会话不可用

Ios 自定义NSURLProtocol子类对后台会话不可用,ios,nsurlprotocol,Ios,Nsurlprotocol,从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 +[NSURLProtoc

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的可选类对象数组。
在确定是否
该类的实例可用于给定的URL方案。
您不应该使用+[NSURLProtocol registerClass:],因为
方法将使用默认会话注册您的类
而不是使用NSURLSession实例。
自定义NSURLProtocol子类对后台不可用
会议。
*/
@属性(可空,复制)NSArray*协议类;
自定义NSURLProtocol子类对后台不可用 会议


限制自定义NSURLProtocol子类仅在前台会话中触发有什么好处

来自苹果文档:

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

苹果根本没有提供一种方法将您的
NSURLProtocol
子类注入到另一个由iOS自己管理的进程中


同样的限制也适用于
WKWebView

,实际上比这更微妙。它永远不会将您的代码注入另一个进程。现在,后台会话使用NSXPC调用应用程序中的委托方法。如果你的应用程序不在那里,它会尽其所能,在某些情况下,你的应用程序会重新启动。如果协议处理必须通过你的应用程序,没有你的应用程序运行,它将永远无法做任何有用的事情,这将完全打破基本层面的后台模型。对于WKWebView,我只能假设原因是所有这些XPC请求造成的性能损失。。。。