2012-02-25 36 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]; 

}