iOS:强制 UIWebView 重新加载/阻止缓存



我有一个显示网站的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;
}

这是我的观点将出现方法:

- (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];

答案只是下一个问题。对于矿石的完整答案:不带缓存的 UI 网络视图

最新更新