2016-08-14 15 views
0

私は、ユーザーがサインインする必要があるアプリを開発しています。ユーザーが私のアプリにログインし、そのセッションがサーバー上で管理されているとします。ネットワーク上の問題またはその他の理由により、セッションは今後サーバー上で期限切れになります。その後、任意のサーバー要求に対して、サーバーは不正な要求をスローします。私はこの状況をキャッチし、彼のセッションが期限切れであり、再ログインする必要があることをユーザーに警告します.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]; 
} 
+0

あなたの質問は分かりません。以前のView Controllerにセッションが期限切れであり、SignInViewControllerを提示する必要があることを通知する必要がありますか? –

+0

いいえ、表示する必要はありません。私はSignInViewControllerを提示したいだけです。私の質問は、すでに提示されたビューに起こったことです。編集した質問を確認してください。 –

答えて

0

で起こっただろうか、最後のステップの後に知りたいですコントローラをViewControllerBの上に置くと、View Controllerは直前のView Controllerをカバーします。現在スタックにあるすべてのView Controllerはメモリ内に残ります。また、ログインアクションの成功または失敗について、以前のビューコントローラにまたはNSNotificationで通知することもできます。

SOFには、このトピックに関する他の質問があります。このトピックでは、View Controllerのライフサイクルをより明確にすることができます。これは:Releasing ViewControllers form memory inside a UINavigationController

+0

ええ、それは私の心配です。古いViewControllerをメモリに保持しておくと、ユーザーが再びSignInに強制されることはありません。 –

関連する問題