LoginSignup
30
28

More than 5 years have passed since last update.

UILocalNotificationがタップされたときに実行される箇所3パターン

Last updated at Posted at 2014-03-10

全てUIApplicationDelegateに書きます。(普通はHogeApplicationDelegate.mですかね)

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    NSDictionary* userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
    if (userInfo != nil) {
        //パターン1:アプリのプロセスが完全に切れていた時に通知をタップ
    }

    return YES;
}

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
    if (application.applicationState == UIApplicationStateActive) {
        //パターン2:画面が既に表示されていて通知が飛んできた時に勝手に呼ばれる
        return;
    }

    if (application.applicationState == UIApplicationStateInactive) {
        //パターン3:アプリがバックグラウンドでは生きている時に通知をタップ
        return;
    }
}
30
28
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
30
28