我正在以这种方式加载数据:
var request = NSURLRequest(URL: url!, cachePolicy: NSURLRequestCachePolicy.ReturnCacheDataElseLoad, timeoutInterval: Double.infinity);
if IJReachability.isConnectedToNetwork(){
request = NSURLRequest(URL: url!, cachePolicy: NSURLRequestCachePolicy.UseProtocolCachePolicy, timeoutInterval: Double.infinity);
}
subtitleLabel.loadRequest(request);
它适用于我,包括缓存。唯一的问题是它不会缓存页面中的图像而且加载速度很慢..有没有办法缓存它们?
(我知道我还在使用旧的XCODE,但我还无法更新)
返回的HTML标头:
Array
(
[Host] => ***.nl
[Connection] => keep-alive
[Cache-Control] => max-age=0
[Accept] => text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
[Upgrade-Insecure-Requests] => 1
[User-Agent] => Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.93 Safari/537.36
[Accept-Encoding] => gzip, deflate, sdch
[Accept-Language] => en-US,en;q=0.8,hr;q=0.6,nl;q=0.4
[Cookie] => PHPSESSID=dnvrv65pbvmrbfhi9kfskjb715
[GEOIP_ADDR] => 84.25.56.128
[GEOIP_CONTINENT_CODE] => EU
[GEOIP_COUNTRY_CODE] => NL
[GEOIP_COUNTRY_NAME] => Netherlands
[Content-Length] => 0
)