webview loadRequest

时间:2023-03-10 04:26:39
webview loadRequest
// 所构建的NSURLRequest具有一个依赖于缓存响应的特定策略,cachePolicy取得策略,timeoutInterval取得超时值
[self.yourSite loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.urlString] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:30.0]];

其中:

NSURLRequest默认的cache policy是NSURLRequestUseProtocolCachePolicy, 是最能保持一致性的协议。(默认)

NSURLRequestReloadIgnoringCacheData 忽略缓存直接从原始地址下载

NSURLRequestReturnCacheDataElseLoad 只有在cache中不存在data时才从原始地址下载

NSURLRequestReturnCacheDataDontLoad 允许app确定是否要返回cache数据,如果使用这种协议当本地不存在response的时候,创建NSURLConnection or NSURLDownload实例时将会马上返回nil;这类似于离线模式,没有建立网络连接;