Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于浏览器前进后退网页刷新的问题 #16

Open
SoulmateL opened this issue Aug 6, 2018 · 5 comments
Open

关于浏览器前进后退网页刷新的问题 #16

SoulmateL opened this issue Aug 6, 2018 · 5 comments
Labels

Comments

@SoulmateL
Copy link

网页后退的时候会刷新呢。感觉不是很科学呢,是否有办法解决吗?

@zhongwuzw
Copy link
Owner

解决方法是监控点击事件,采用多窗口的机制,自己来管理前进后退,注意点是内存问题,因为UIWebView本身占用内存比较大,需要采取一些策略,比如只保留适当数量的UIWebView,内存警告时移除UIWebView,具体你可以参考一下我项目中长按链接,新窗口打开的模式,实现方法类似。

@SoulmateL
Copy link
Author

恩,可能是我表达的有问题吧!就是调用goback会刷新webview,我根据网上的方法设置了cacheModel = WebCacheModelPrimaryWebBrowser但是好像没有生效呢

@zhongwuzw
Copy link
Owner

如果仅仅是想尝试优化一下后退的效果的话,试试如下代码吧。但是我本人还是不太建议使用这种方法,UIWebView在内存方面做得不好,所以需要做一些清除缓存的操作。自己维护前进后退列表的话,可以控制缓存的数量,根据实际应用控制平衡。

[[NSUserDefaults standardUserDefaults] setInteger:2 forKey: @"WebKitCacheModelPreferenceKey"];
id webView = [uiWebView valueForKeyPath:@"_internal.browserView._webView"];
id preferences = [webView valueForKey:@"preferences"];
[preferences performSelector:NSSelectorFromString(@"_postCacheModelChangedNotification")];

@SoulmateL
Copy link
Author

好的,谢谢你了

@zhongwuzw
Copy link
Owner

zhongwuzw commented Aug 9, 2018

@SoulmateL 不客气,友情提示,请不要在生产环境下使用这种KVC的方式来访问私有函数(私有函数需要转换一下,防止被拒),防止Crash. 建议使用msgSendrespondsTo...等类似方式一步步判断是否存在,然后再访问。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants