简体   繁体   中英

FCM/IOS, how to know if an user tapped on a notification alert or if we receive the notification directly?

on ios 9 and below, when an user click on a notification alert , it's fire the event applicationDidReceiveRemoteNotification but when the app is in foreground the notification arrive straight away to the app without showing any alert to the end user, and the event applicationDidReceiveRemoteNotification is also called :(

so how to know if the user click on a notification alert (maybe an old one) or if we receive the notification straight away because the app was in foreground ?

You can check the application states like this.

if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateActive) {
    // Just received notification (Foreground)
} else if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateInactive) {
    // launched by taping notification
} else if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) {
    // Just received notification (Background)
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM