ViewController のクラス内のどのメソッドを呼び出して、フォアグラウンドに移動したかを確認できますか?
たとえば、自分のアプリケーションのページを見ていて、アプリケーションを閉じて後で戻ることにしました。戻ってみると、私が見ていたのと同じビューが画面に表示されていました。しかし... アプリケーションを開くとすぐに、別のビューに移動したいと思います。
これどうやってするの?
現在これを試しています:
- (void) applicationDidBecomeActive:(NSNotification*) notification
{
[self checkActivity];
// Do your stuff here
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationWillEnterForeground:)
name:UIApplicationWillEnterForegroundNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationDidBecomeActive:)
name:UIApplicationDidBecomeActiveNotification
object:nil];
}
return self;
}
- (void)checkActivity{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSLog(@"Checking if re-authentication required...");
if([[defaults objectForKey:@"shouldgotologin"] isEqualToString:@"yes"]){
NSLog(@"View Should go to login...performing segue");
[defaults setObject:@"no" forKey:@"shouldgotologin"];
[defaults synchronize];
[self performSegueWithIdentifier:@"backtologin" sender:self];
} else {
NSLog(@"Should go to login is not true.");
}
}