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

标签 ios react-native push-notification apple-push-notifications 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);
   },
...
}

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

最佳答案

我不得不在 ios 文件中添加一些配置 AppDelegate.m关注此 gist确实使它工作。
我的代码看起来像:

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);
    }
  }
},
我也设置了popInitialNotificationtrue

关于ios - React-native:使用 zo0r/react-native-push-notification 显示前台通知,如后台通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60799054/

相关文章:

javascript - 使用 UIWebview 中的 JSContext 会使我的应用程序被拒绝吗?

firebase - react native firebase 'average' 查询?

reactjs - Flex React Native FlatList child 长到全高?

android - React Native 中的推送通知

ios - 注册远程通知失败

ios - Tesseract iOS 相机精度低

ios - Alamofire 2.0 和 Swift 2 - 标题不工作。查看如何修复它

ios - iOS App第一个版本应该是1.0还是1.0.0?

reactjs - 如何在 native react 中关闭模式

swift - 关闭解析推送状态