ios – 检测应用程序是否从推送通知启动/打开

是否可以知道应用程序是否从推送通知启动/打开?

我想这个发射事件可以在这里抓住:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    if (launchOptions != nil) {
         // Launched from push notification
         NSDictionary *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];

    }
}

但是,我如何检测它是从应用程序在背景时的推送通知打开?

最佳答案
查看代码:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    if ( application.applicationState == UIApplicationStateInactive || application.applicationState == UIApplicationStateBackground  )
    {
         //opened from a push notification when the app was on background
    }
}

与…一样

-(void)application:(UIApplication *)application didReceiveLocalNotification (UILocalNotification *)notification

转载注明原文:ios – 检测应用程序是否从推送通知启动/打开 - 代码日志