2012-02-25 78 views
1

我有一個UIViewController它包含一個UIWebView從UIWebView一旦關閉釋放內存/ cookie /緩存

我使用UIViewController中的UIWebview登錄到Facebook說的網站,然後點擊完成,這會關閉視圖控制器,我想這會釋放視圖控制器。但是當我再次打開UIWebview(無需退出應用程序,甚至在終止應用程序後)網頁仍然在Web視圖加載後登錄到Facebook。我應該如何發佈網絡視圖,以便每次點擊完成並返回到網絡視圖時,網絡視圖總是會像「全新」一樣登錄到我以前登錄過的任何網站。

- (void)viewDidLoad{ 
     NSLog(@"webView viewDidLoad called"); 
     appDelegate = (LoginDBAppDelegate *)[[UIApplication sharedApplication] delegate]; 
     loginObj = [appDelegate.loginArray objectAtIndex:currentSelectedRow]; 

     myWebView.delegate = self; 
     [super viewDidLoad]; 
     [self showWebView]; 

} 

-(void)showWebView{ 
    NSLog(@"webView showWebView called"); 

    NSURL *url = [NSURL URLWithString:loginObj.loginURL]; 
    NSURLRequest *request = [NSURLRequest requestWithURL:url]; 


    [myWebView loadRequest:request]; 
} 


-(IBAction)done_Clicked:(id)sender{ 
    NSLog(@"webView Done_Clicked"); 

    //dismiss the controller 
    [self.navigationController dismissModalViewControllerAnimated:YES]; 

} 

-(void)dealloc{ 
     [myWebView release]; 
     myWebView.delegate = nil; 
     [activity release]; 
     [urlTextField release]; 
     [super dealloc]; 
} 

我都試過,但沒有奏效:

-(IBAction)done_Clicked:(id)sender{ 
NSLog(@"webView Done_Clicked"); 

[[NSURLCache sharedURLCache] removeAllCachedResponses]; 
[myWebView stringByEvaluatingJavaScriptFromString:@"var body=document.getElementsByTagName('body')[0];body.style.backgroundColor=(body.style.backgroundColor=='')?'white':'';"]; 
[myWebView stringByEvaluatingJavaScriptFromString:@"document.open();document.close()"]; 

//dismiss the controller 
[self.navigationController dismissModalViewControllerAnimated:YES]; 

} 

我也試過這種沒有任何成功:

- (void) viewDidDisappear:(BOOL)animated { 

NSLog(@"webView viewDidDisappear called"); 
[super viewDidDisappear:animated]; 

[self.myWebView removeFromSuperview]; 
self.myWebView.delegate = nil; 
self.myWebView = nil; 
[myWebView release]; 
} 

回答

2

得到的答案從有人在論壇上,所以信貸給他...

將代碼位於檢索單元中

//Set Cache 
NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil]; 
[NSURLCache setSharedURLCache:sharedCache]; 

//Clear All Cookies 
for(NSHTTPCookie *cookie in [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]) { 

    //if([[cookie domain] isEqualToString:someNSStringUrlDomain]) { 

    [[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie]; 

}