且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

iOS / XCode:如何知道该应用程序已经启动与点击通知或在跳板应用程序图标?

更新时间:2022-11-25 14:51:16

输入代码:

   - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{
UILocalNotification * notification = launchOptions [UIApplicationLaunchOptionsLocalNotificationKey] ;

if(notification){
//从通知启动
} else {
//从跳板
}
}

UIApplicationDelegate 。 p>

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 notification center) ?
  • or the app icon on the springboard ?

Thanks !!

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.