現在、メイン ビューとログイン ビューがあります。ログイン ビュー (javascript インジェクションと Web スクレイピング) で認証を処理し、メイン ビューに適切なコンテンツを読み込みます。問題は、メイン ビューにログアウト ボタンを表示したいことです。私がやりたいことは、ログインビュー(ログアウトURL)のuiwebviewにロードURLリクエストを送信することです。ログインビューを表示せずにやりたい。これは可能ですか?
ありがとう!!
これは、LoginView で行っていることです。
- (void)webViewDidFinishLoad:(UIWebView *) webView {
if ( [[NSURL URLWithString:@"https://arandomservice.com/signin"] isEqual:[NSURL URLWithString:[WebView stringByEvaluatingJavaScriptFromString: @"document.URL"]]] ) {
NSLog(@"Authentication Successful");
//Save Username
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:usernameField.text forKey:@"username"];
[defaults synchronize];
//Save Password
[defaults setObject:passwordField.text forKey:@"password"];
[defaults synchronize];
//Close Login Screen
[self dismissViewControllerAnimated:YES completion:NULL];
}
else {
NSLog(@"Authentication Failed.");
}
}
後で、ユーザーをログアウトさせたいときは、次のことを行う別のビューで uibutton を押してもらいたい:
NSURL *signInUrl = [NSURL URLWithString:@"https://arandomservice.com/logout"];
[self loadURL:nil withURL:signInUrl];
これをログインビューに送信したいと思います。これを達成する最良の方法は何ですか?(PS 後で NSuserdefaults の代わりにキーチェーンを使用することに注意してください)。