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

前端 未结 3 2040
失恋的感觉
失恋的感觉 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 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
    }
    

提交回复
热议问题