iOS / XCode: how to know that app has been launched with a click on notification or on springboard app icon?

后端 未结 2 1676
抹茶落季
抹茶落季 2020-12-29 14:53

I would like to know if there is a way to know if an app (which can be closed or open in background) has been launched with a click on:

  • a notification (in the
2条回答
  •  死守一世寂寞
    2020-12-29 15:42

    put this code:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        UILocalNotification *notification = launchOptions[UIApplicationLaunchOptionsLocalNotificationKey];
    
        if (notification) {
            // launched from notification
        } else {
            // from the springboard
        }
    }
    

    in your UIApplicationDelegate.

提交回复
热议问题