私は、ユーザーがサインインする必要があるアプリを開発しています。ユーザーが私のアプリにログインし、そのセッションがサーバー上で管理されているとします。ネットワーク上の問題またはその他の理由により、セッションは今後サーバー上で期限切れになります。その後、任意のサーバー要求に対して、サーバーは不正な要求をスローします。私はこの状況をキャッチし、彼のセッションが期限切れであり、再ログインする必要があることをユーザーに警告します.Cleared NSUserDefaults
も同様です。 Alert OK button
をクリックすると、signInページがユーザーに提示されます。
ここで私の質問は正しいですか? ViewControllerドキュメンテーションから、presenting ViewController
の上にpresented ViewController
が表示されることが示されています。だから私は、SignInViewController
を提示した後、私の以前のViewControllerに何が起こったのかを知りたいのですが、メモリがリークするか、予期しない動作が起こるでしょうか?質問を明確にするために以下のフローを追加しました。私はあなたがモーダルビューを提示しているのでViewControllerBセッションが終了した後にログインページを表示
SignInViewController> ViewControllerA> ViewControllerB>(セッションが期限切れ)> AlertViewController>(提示)SignInViewController
- (void)presentLoginScreenAfterSessionIsExpired
{
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"employeeId"];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"userName"];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"emailId"];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"profileImageData"];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"role"];
/** showing alert to the User **/
UIAlertController *alert = [UIAlertController alertControllerWithTitle:
@"Oops!" message:@"Your Session Has Been Expired, Please Re-Login"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:
NSLocalizedString(@"OK", @"OK Action")
style:UIAlertActionStyleDefault handler:^(UIAlertAction *action)
{
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
/** presenting signInViewController **/
UIViewController *vc = [storyBoard instantiateViewControllerWithIdentifier:
@"signInViewController"];
[self presentViewController:vc animated:YES completion:NULL];
}];
[alert addAction:okAction]; // Here action is added to alert controller.
[self presentViewController:alert animated:YES completion:nil];
}
あなたの質問は分かりません。以前のView Controllerにセッションが期限切れであり、SignInViewControllerを提示する必要があることを通知する必要がありますか? –
いいえ、表示する必要はありません。私はSignInViewControllerを提示したいだけです。私の質問は、すでに提示されたビューに起こったことです。編集した質問を確認してください。 –