小编典典

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

all

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

我想启动事件可以在这里捕获:

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

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

    }
}

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


阅读 64

收藏
2022-07-30

共1个答案

小编典典

请参阅此代码:

- (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
2022-07-30