gpt4 book ai didi

objective-c - iOS : Force UIWebView to reload/prevent caching

转载 作者:太空狗 更新时间:2023-10-30 03:36:28 24 4
gpt4 key购买 nike

我有一个显示网站的 iPhone 应用程序。该网站会不时更改其内容,但我的应用程序不会在每次打开时都重新加载。我试图阻止网站的缓存,但没有成功。

这是我的初始化方法:

- (id)init:(NSString *)url withTitle:(NSString *)theTitle withPageName:(NSString *)pageName {
self = [super init];
if(self) {
NSLog(@"websiteviewcontroller init");
self.title = theTitle;
self.url = url;
self.pageName = pageName;

CGRect frame = [[UIScreen mainScreen] applicationFrame];
webView = [[UIWebView alloc] initWithFrame:frame];

NSURL *theURL = [NSURL URLWithString:url];
[webView loadRequest:[NSURLRequest requestWithURL:theURL]];

// support zooming
webView.scalesPageToFit = YES;

//[[NSURLCache sharedURLCache] removeAllCachedResponses];
[webView reload];

}
return self;
}

这是我的 viewWillAppear 方法:

- (void)viewWillAppear:(BOOL)animated {

CGRect frame = [[UIScreen mainScreen] applicationFrame];
webView = [[UIWebView alloc] initWithFrame:frame];

NSURL *theURL = [NSURL URLWithString:url];
[webView loadRequest:[NSURLRequest requestWithURL:theURL]];

[webView reload];

// support zooming
webView.scalesPageToFit = YES;
}

请帮我解决这个问题。非常感谢所有答案。

最佳答案

这段代码片段解决了我的问题:

[[NSURLCache sharedURLCache] removeAllCachedResponses];

关于objective-c - iOS : Force UIWebView to reload/prevent caching,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10962256/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com