Free memory / cookie / cache from UIWebView after closing

I have a UIViewController that contains a UIWebView .

i go to the site to tell facebook using the UIWebview in the UIViewController, after which I click on done which reject the view controller, which I suppose will free the view controller. but when I reopen UIWebview (without leaving the application, and even after the application is completed), the webpage still logs into Facebook after the webview is loaded. How should I let go of the web view so that every time I click the "Done" button and return back to the web view, the web view will always be reminiscent of the "new" and not the login on any website to which I entered earlier.

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

I tried this, but this did not work:

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

I also tried this without any success:

 - (void) viewDidDisappear:(BOOL)animated { NSLog(@"webView viewDidDisappear called"); [super viewDidDisappear:animated]; [self.myWebView removeFromSuperview]; self.myWebView.delegate = nil; self.myWebView = nil; [myWebView release]; } 
+1
source share
1 answer

I received a response from someone on the forum, so a loan to him ...

Put this code in viewDidLoad

 //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]; } 
+2
source

Source: https://habr.com/ru/post/982184/


All Articles