React-native:使用 zo0r/react-native-push-notification 显示前台通知,如后台通知

Sim*_*mon 6 push-notification apple-push-notifications ios react-native react-native-push-notification

我已经使用zo0r / react-native-push-notification在我的 React-native 应用程序上设置了推送通知。当应用程序处于后台模式时,它适用于 Android 和 iOS。

但是,当应用程序处于 iOS 的前台模式时,不会显示通知。我知道我必须在前台模式下处理通知,但我想以与后台模式下完全相同的方式显示它们。

所以我做了以下事情:

import {PushNotificationIOS} from 'react-native';

PushNotification.configure({
...
   onNotification: function(notification) {
      if (notification.foreground) {
         PushNotification.localNotification(notification);
      }
      notification.finish(PushNotificationIOS.FetchResult.NoData);
   },
...
}
Run Code Online (Sandbox Code Playgroud)

但是没有任何反应,通知仍然没有显示,我错过了什么?

Sim*_*mon 2

我必须在 ios 文件中添加一些配置AppDelegate.m

遵循这个要点确实让它发挥了作用。

我的代码如下所示:

onNotification(notification) {
  if (isIos) {
    if (
      notification.foreground &&
      (notification.userInteraction || notification.remote)
    ) {
      PushNotification.localNotification(notification);
    }
    notification.finish(PushNotificationIOS.FetchResult.NoData);
  } else {
    if (notification.foreground) {
      PushNotification.localNotification(notification);
    }
  }
},
Run Code Online (Sandbox Code Playgroud)

我也设置popInitialNotificationtrue