UIViewController
にはUIWebView
が含まれています。UIWebViewから一度メモリ/ Cookie /キャッシュを解放すると
私はUIViewControllerでUIWebviewを使用してfacebookのWebサイトにログインしてから、doneをクリックしてView Controllerを閉じると、View Controllerが解放されます。しかし、UIWebviewをもう一度開くと(アプリを終了しなくても、アプリを終了した後でも)、Webビューが読み込まれた後、WebページはFacebookにまだログインしています。私はどのように私が完了をクリックし、Webビューに戻るときに、いつでも私が以前にログオンしていた任意のウェブサイトへのログオンではなく、 "まったく新しい"ようなものになるように、Webビューをリリースする必要があります。
- (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];
}