8

I have an iPhone app that shows a website. This website changes it's content from time to time but my app doesn't reload it every time it is opened. I tried to prevent the caching of the site, but without success.

This is my init method:

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

This is my viewWillAppear-Method:

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

Please help me to solve this problem. All answers are much appreciated.

Askolein
  • 3,250
  • 3
  • 28
  • 40
nimrod
  • 5,595
  • 29
  • 85
  • 149

2 Answers2

11

This code snipplet fixed my problem:

[[NSURLCache sharedURLCache] removeAllCachedResponses];
nimrod
  • 5,595
  • 29
  • 85
  • 149
0

The answer is just for the next question. For a ore complete answer: UIwebview without Cache

Community
  • 1
  • 1
Rivera
  • 10,792
  • 3
  • 58
  • 102