私のプロジェクトの非活動的な実装です。私はプロジェクトのRootViewControllerクラスでNSNotificationを作成しました。目的地cでのセッションの非アクティブ化のためのnsnotificationアプローチ
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle: @"Close"
style: UIBarButtonItemStyleDone
target: self
action: @selector(closeModal)];
UIImage *image = [UIImage imageNamed:@"fidelity_logotype"];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, image.size.width, image.size.height)];
[imageView setImage:image];
[self.navigationItem setTitleView:imageView];
self.navigationController.view.backgroundColor = [UIColor fidelityGreen];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidTimeout:) name:@"ApplicationTimeout" object:nil];
}
- (void) applicationDidTimeout:(NSNotification *) notif
{
NSLog(@"I m here");
BCDSessionInactivityViewController *sessionView=[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"InactivityViewController"];
sessionView.modalPresentationStyle = UIModalPresentationFormSheet;
sessionView.preferredContentSize = CGSizeMake(838,340);
[[self topViewController] presentViewController:sessionView animated:YES completion:nil];
}
とlogoutviewcontrollerで、私は
- (IBAction)logoutbtn:(id)sender
{
NSLog(@"logout is called");
[sessionTimer invalidate];
sessionTimer = nil;
[[BCDTimeManager sharedTimerInstance]stopIdleTimer];
//[self dismissViewControllerAnimated:YES completion:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"ApplicationTimeout" object:nil];
[self performSegueWithIdentifier:@"Thankyoupage" sender:self];
}
これは私が通知を掲示コードで下に書かれたこのオブザーバを削除しています。初めてのログインのための
- (void)idleTimerExceeded {
NSLog(@"idle time exceeded");
[[NSNotificationCenter defaultCenter]
postNotificationName:@"ApplicationTimeout" object:nil];
}
は、それがタイマーを超えたときに、私は通知し、モデルビューを投稿完璧presesntedされますが、ユーザーがログアウトすると、その通知が掲載されるたびに、セレクタメソッドの後に二回呼ばなっている正常に動作します
通知が1回だけ投稿されていることは間違いありません。
すべてのビューコントローラで通知を作成し、ビューのアンロード時に削除する必要がありますか?
私はここで間違っていますか?
を除去するための
removeObserver
を呼び出すあなたはOK通知オブザーバを追加しましたが、あなたは通知をポストどこ私は見ていませんよ。通知ポストは一度だけ呼び出されていますか?一度しか呼ばれていないことを確認するためにそこにログを記録しましたか? – fsb@fbara通知を掲示しているコードを追加しました。通知は一度だけ通知されていますが、メソッドは2回呼び出されていることは確かです – Nitya
もちろん、すべてのVCで新しい通知を作成する必要はありませんでした。コード内のある場所からのみ 'idleTimerExceeded'を呼び出していますか? – fsb