2012-06-09 3 views
6

J'ai une application pour iPhone qui montre un site Web. Ce site change son contenu de temps en temps mais mon application ne le recharge pas à chaque fois qu'il est ouvert. J'ai essayé d'empêcher la mise en cache du site, mais sans succès.iOS: Forcer UIWebView à recharger/empêcher la mise en cache

Ceci est ma méthode init:

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

Ceci est mon viewWillAppear-Méthode:

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

S'il vous plaît aidez-moi à résoudre ce problème. Toutes les réponses sont très appréciées.

Répondre

10

Ce code snipplet fixe mon problème:

[[NSURLCache sharedURLCache] removeAllCachedResponses]; 
Questions connexes