LoginSignup
8
8

More than 5 years have passed since last update.

AppDelegate以外にActiveになったことを通知する

Last updated at Posted at 2014-02-08

例えば、UIViewControllerの派生クラスでは、このような感じで通知されるように設定できます。

- (void) viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillResignActive) name:UIApplicationWillResignActiveNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActive) name:UIApplicationDidBecomeActiveNotification object:nil];
}

- (void) viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)applicationWillResignActive
{
    // Activeでなくなる時の処理.
}

- (void)applicationDidBecomeActive
{
    // Activeになった時の処理.
}

8
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
8