iOSのアプリでUIAlertControllerを使用して、一定時間が経つとログアウトポップアップが出て、OKを押すとログアウトされるタイマーを作成しています。
ポップアップやアラート等が出ていない通常のWebViewの画面ではタイマーが起動してログアウトのポップアップを表示してくれるのですが、
他のポップアップ等が出ている時にはログアウトのアラートが出てくれません。
ログを出してみたところ、
Warning: Attempt to present <UIAlertController: 0x7fc764612600> on <WebViewController: 0x7fc761f970a0> which is already presenting (null)
と、ログアウトしてほしい秒数までカウントされた後、表示されてしまっています。
UIAlertControllerではアラートを複数同時に出せないことは調べてわかりましたが、そのアラートを無視?して、ログアウトのアラートを出し、OKを押してログアウトさせる方法がわかりません。
恐縮ですが、ご教授願います。
Objective
1 2/* WebViewController */ 3 4/* 最終操作の有効チェック */ 5- (void)checkTimeFromLatestOperation:(NSTimer *)timer 6{ 7 // 現在時刻と最終操作時間の差分が24分以上の場合、ログアウトする 8 NSTimeInterval now = [NSDate date].timeIntervalSince1970; 9 10 AppSettingsUtility *utility = [[AppSettingsUtility alloc] init]; 11 NSTimeInterval latestTime = [utility latestOperationTime]; 12 13 NSTimeInterval diff = now - latestTime; 14 NSLog(@"%f", diff); 15 if (diff >= [utility timeOutSeconds]) { 16 [self showLogoutAlert:NSLocalizedString(@"ForceLogoutMessage", 17 @"強制ログアウト時のメッセージ") 18 isForced:YES]; 19 // 有効チェックのタイマーをストップする 20 [_timer invalidate]; 21 _timer = nil; 22 } 23} 24 25 26/* ログアウトのアラート表示 */ 27- (void)showLogoutAlert:(nonnull NSString *)message isForced:(BOOL)isForced 28{ 29 UIAlertController *alert = 30 [UIAlertController alertControllerWithTitle:nil 31 message:message 32 preferredStyle:UIAlertControllerStyleAlert]; 33 UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil) 34 style:UIAlertActionStyleDefault 35 handler:^(UIAlertAction *_Nonnull action) { 36 [self requestLogoutApiConnector]; 37 }]; 38 [alert addAction:okAction]; 39 if (!isForced) { 40 UIAlertAction *cancelAction = 41 [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) 42 style:UIAlertActionStyleCancel 43 handler:^(UIAlertAction *_Nonnull action){ 44 }]; 45 [alert addAction:cancelAction]; 46 } 47 [self presentViewController:alert animated:YES completion:nil]; 48} 49
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。