Why not login to Qiita and try out its useful features?

We'll deliver articles that match you.

You can read useful information later.

20
19

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

UIApplicationの変更通知一覧

Posted at

UIApplicationの変更通知はObserverで受け取ることができます。
そこで受け取れる通知を下記にまとめました。

UIApplicationのNotifications(通知)一覧

パラメータ 説明
UIApplicationDidEnterBackgroundNotification アプリケーションがバックグラウンドに入る時に通知
UIApplicationWillEnterForegroundNotification アプリケーションがアクティブになる直前に通知
UIApplicationDidFinishLaunchingNotification アプリケーションが起動した直後に通知
UIApplicationDidBecomeActiveNotification アプリケーションがアクティブになった時に通知
UIApplicationWillResignActiveNotification アプリケーションがアクティブで無くなる直前に通知
UIApplicationDidReceiveMemoryWarningNotification メモリ使用量の警告の通知
UIApplicationWillTerminateNotification アプリケーションが終了される直前に通知
UIApplicationSignificantTimeChangeNotification 日付の変更を通知
UIApplicationWillChangeStatusBarOrientationNotification デバイスの向きが変わる直前に通知
UIApplicationDidChangeStatusBarOrientationNotification デバイスの向きが変わった直後に通知
UIApplicationWillChangeStatusBarFrameNotification ステータスバーのサイズ変更される直前に通知
UIApplicationDidChangeStatusBarFrameNotification ステータスバーのサイズ変更された直後に通知
UIApplicationBackgroundRefreshStatusDidChangeNotification 端末の[Appのバックグラウンド更新]がオフにされ、再度アプリがアクティブになった時に通知されます
UIApplicationProtectedDataWillBecomeUnavailable 保護されたファイル(*1)へコードからアクセス出来なくなる直前に通知
UIApplicationProtectedDataDidBecomeAvailable 保護されたファイル(*1)へコードからアクセスが可能になった時に通知

*1 保護されたファイル(保護ファイル)については詳しくは「iOS App Programming Guid」の「Protecting Data Using On-Disk Encryption」の項目を参照

使用方法

オブザーバに変更通知を登録する

.m
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(hoge:)
                                                 name:UIApplicationDidBecomeActiveNotification
                                               object:nil];

変更通知を受け取る

.m
- (void)hoge:(NSNotification *)notification
{
    
}

通知を削除する場合

.m
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:UIApplicationDidBecomeActiveNotification
                                                  object:nil];

NSNotificationCenterに対する全ての通知を削除する場合

.m
    [[NSNotificationCenter defaultCenter] removeObserver:self];

参考元

下記のサイト、ブログを参考にしました。
■[iPhoneプログラミング]UIApplicationのNotificationsの一覧 - 強火で進め
【iOS】続・アプリがバックグラウンド・フォアグラウンド状態になった時の実行処理 - 日本VTR実験室
■ [iPhone][develop] アプリ終了時に呼ばれるメソッドをAppDelegate以外にも登録する - Ni chicha, ni limona - 平均から抜けられない

20
19
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

Qiita Conference 2025 will be held!: 4/23(wed) - 4/25(Fri)

Qiita Conference is the largest tech conference in Qiita!

Keynote Speaker

ymrl、Masanobu Naruse, Takeshi Kano, Junichi Ito, uhyo, Hiroshi Tokumaru, MinoDriven, Minorun, Hiroyuki Sakuraba, tenntenn, drken, konifar

View event details
20
19

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?