【问题标题】:iOS: Force UIWebView to reload / prevent cachingiOS:强制 UIWebView 重新加载/阻止缓存
【发布时间】:2012-06-13 07:18:33
【问题描述】:

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

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

【问题讨论】:

    标签: objective-c ios5 uiwebview


    【解决方案1】:

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

    [[NSURLCache sharedURLCache] removeAllCachedResponses];
    

    【讨论】:

      【解决方案2】:

      答案只针对下一个问题。要获得完整的答案: UIwebview without Cache

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-07-02
        • 1970-01-01
        • 2021-04-12
        • 1970-01-01
        • 1970-01-01
        • 2015-01-28
        • 1970-01-01
        • 2019-09-03
        相关资源
        最近更新 更多