ios: detect app was started by tapping message in notification center

前端 未结 3 2027
失恋的感觉
失恋的感觉 2021-01-26 12:38

Is there a way to know if the app was started by tapping message in notification center?

I want to make some calls to server only if the app is started by tapping on a m

相关标签:
3条回答
  • 2021-01-26 12:54

    Yes you can find application launching reason in

    - (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;
    
    }
    
    0 讨论(0)
  • 2021-01-26 12:55

    In - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions method of the application delegate, you will receive the notification information in the launchOptions dictionary. That way you could get to know that the app was launched from the notification tray.

    0 讨论(0)
  • 2021-01-26 13:06

    You can handle push notification like

    - (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
      ....
    }
    

    Some times application is in active state and still we want to handle push notification than below method will be called

    - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
    {
        //Application did receive push notification. Do whatever you want to do
    }
    
    0 讨论(0)
提交回复
热议问题