ios:通过点击通知中心的消息启动检测应用程序

有没有办法通过点击通知中心的消息来了解应用程序是否已启动?

我想通过点击通知中心的消息启动应用程序时,只对服务器进行一些调用。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions应用程序委托的- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions方法,您将在launchOptions字典中收到通知信息。 这样你就可以知道应用程序是从通知托盘启动的。

是的,您可以在中找到应用程序启动原因

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // keys can be UIApplicationLaunchOptionsLocalNotificationKey NSDictionary *notificationPayload = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]; if(notificationPayload) { // application launch because of notification // do some stuff here } return YES; } 

您可以处理推送通知

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { NSDictionary *pushNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; if (pushNotification) { //Application did started by clicking push notification. Do whatever you want to do } ....//Your rest code .... } 

有时应用程序处于活动状态,我们仍然希望处理推送通知,而不是调用以下方法

 - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { //Application did receive push notification. Do whatever you want to do }