ios WebView 页面缓存

code4app里面的代码。。

核心代码。。。

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {

    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {

        CustomURLCache *urlCache = [[CustomURLCache alloc] initWithMemoryCapacity:20 * 1024 * 1024

                                                                     diskCapacity:200 * 1024 * 1024

                                                                         diskPath:nil

                                                                        cacheTime:0];

        [CustomURLCache setSharedURLCache:urlCache];

    }

    returnself;

扫描二维码关注公众号,回复: 562240 查看本文章

 

}

 

 

 ios8,添加到我的项目中,这个方法有点问题。。。。需要用gitHub里面的一个demo才可以。。。

https://github.com/rnapier/RNCachingURLProtocol

 

在进入webVIew页面的时候。。。。。

 [NSURLProtocolunregisterClass:[RNCachingURLProtocolclass]];///开启自定义的webview缓存方法。

 

离开webVIew的时候。。。

 [NSURLProtocolregisterClass:[RNCachingURLProtocolclass]];///开启自定义的webview缓存方法。

 

 

 

其他都不需要做,,,只要引入相关文件就可以了。。。。

下面是demo。。。。

猜你喜欢

转载自zhangmingwei.iteye.com/blog/2092097