FCM / IOS,如何知道用户是否点击了通知提醒或我们是否直接收到通知?

时间:2017-05-13 17:16:30

标签: ios firebase firebase-cloud-messaging

在ios 9及以下,当用户点击通知提醒时,它会触发事件applicationDidReceiveRemoteNotification,但当应用处于前台时通知直接到达应用程序而不向最终用户显示任何警报,并且还会调用事件applicationDidReceiveRemoteNotification :(

那么如何知道用户是否点击了通知提醒(可能是旧的)或者我们是否因为应用程序位于前台而立即收到通知?

1 个答案:

答案 0 :(得分:1)

您可以检查这样的应用程序状态。

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)
}