iOS-NSURLProtocol的理解与应用

来源:互联网 发布:淘宝电子商务模式 编辑:程序博客网 时间:2024/06/07 07:12

NSURLProtocol官方文档的理解

官方提供的实例与方法如下:

- (instancetype)initWithRequest:(NSURLRequest *)request cachedResponse:(nullable NSCachedURLResponse *)cachedResponse client:(nullable id <NSURLProtocolClient>)client NS_DESIGNATED_INITIALIZER;@property (nullable, readonly, retain) id <NSURLProtocolClient> client;@property (readonly, copy) NSURLRequest *request;@property (nullable, readonly, copy) NSCachedURLResponse *cachedResponse;/*======================================================================  Begin responsibilities for protocol implementors  The methods between this set of begin-end markers must be  implemented in order to create a working protocol.  ======================================================================*/+ (BOOL)canInitWithRequest:(NSURLRequest *)request;+ (NSURLRequest *)canonicalRequestForRequest:(NSURLRequest *)request;+ (BOOL)requestIsCacheEquivalent:(NSURLRequest *)a toRequest:(NSURLRequest *)b;- (void)startLoading;- (void)stopLoading;/*======================================================================  End responsibilities for protocol implementors  ======================================================================*/+ (nullable id)propertyForKey:(NSString *)key inRequest:(NSURLRequest *)request;+ (void)setProperty:(id)value forKey:(NSString *)key inRequest:(NSMutableURLRequest *)request;+ (void)removePropertyForKey:(NSString *)key inRequest:(NSMutableURLRequest *)request;+ (BOOL)registerClass:(Class)protocolClass;+ (void)unregisterClass:(Class)protocolClass;