只需要离线缓存,而不考虑是否失效或过期的情况下(很少不考虑),可以直接进行本地存储和加载
1.NSURLCache设置
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSURLCache *URLCache = [[NSURLCache alloc] initWithMemoryCapacity:1024 * 1024 * 1024
diskCapacity:1024 * 1024 * 1024
diskPath:nil];
[NSURLCache setSharedURLCache:URLCache];
return YES;
}
2.初始化加载
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
_wkWeb = [[WKWebView alloc]initWithFrame:self.view.bounds];
_wkWeb.UIDelegate = self;
_wkWeb.navigationDelegate = self;
[self.view addSubview:_wkWeb];
_url = @"http://www.baidu.com";
NSURL *URL =