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

前端 未结 3 2109
失恋的感觉
失恋的感觉 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    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;
    
    }
    

提交回复
热议问题