React Native Push Notification在XCode控制台中显示,但不在设备上显示

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了React Native Push Notification在XCode控制台中显示,但不在设备上显示相关的知识,希望对你有一定的参考价值。

我已经将react-native-push-notification文档(https://github.com/zo0r/react-native-push-notification)上的指南跟到了T,但是当我在手机上加载应用程序时,我无法生成简单的通知。相反,我可以在XCode控制台中看到通知。否则没有错误。

var PushNotification = require('react-native-push-notification');

PushNotification.configure({

    // (optional) Called when Token is generated (ios and android)
    onRegister: function(token) {
        console.log( 'TOKEN:', token );
    },

    // (required) Called when a remote or local notification is opened or received
    onNotification: function(notification) {
        console.log( 'NOTIFICATION:', notification );

        // process the notification

        // required on iOS only (see fetchCompletionHandler docs: https://facebook.github.io/react-native/docs/pushnotificationios.html)
        notification.finish(PushNotificationIOS.FetchResult.NoData);
    },

    // ANDROID ONLY: GCM Sender ID (optional - not required for local notifications, but is need to receive remote push notifications)
    senderID: "YOUR GCM SENDER ID",

    // IOS ONLY (optional): default: all - Permissions to register.
    permissions: {
        alert: true,
        badge: true,
        sound: true
    },

    // Should the initial notification be popped automatically
    // default: true
    popInitialNotification: true,

    /**
      * (optional) default: true
      * - Specified if permissions (ios) and token (android and ios) will requested or not,
      * - if not, you must call PushNotificationsHandler.requestPermissions() later
      */
    requestPermissions: true,
});

export default class PostList extends Component<{}> 
{
    componentDidMount() {
        PushNotification.localNotification({
              /* Android Only Properties */
              id: '0', // (optional) Valid unique 32 bit integer specified as string. default: Autogenerated Unique ID
              ticker: "My Notification Ticker", // (optional)
              autoCancel: true, // (optional) default: true
              largeIcon: "ic_launcher", // (optional) default: "ic_launcher"
              smallIcon: "ic_notification", // (optional) default: "ic_notification" with fallback for "ic_launcher"
              bigText: "My big text that will be shown when notification is expanded", // (optional) default: "message" prop
              subText: "This is a subText", // (optional) default: none
              color: "red", // (optional) default: system default
              vibrate: true, // (optional) default: true
              vibration: 300, // vibration length in milliseconds, ignored if vibrate=false, default: 1000
              tag: 'some_tag', // (optional) add tag to message
              group: "group", // (optional) add group to message
              ongoing: false, // (optional) set whether this is an "ongoing" notification

              /* iOS and Android properties */
              title: "My Notification Title", // (optional, for iOS this is only used in apple watch, the title will be the app name on other iOS devices)
              message: "My Notification Message", // (required)
              playSound: false, // (optional) default: true
              soundName: 'default', // (optional) Sound to play when the notification is shown. Value of 'default' plays the default sound. It can be set to a custom sound such as 'android.resource://com.xyz/raw/my_sound'. It will look for the 'my_sound' audio file in 'res/raw' directory and play it. default: 'default' (default sound is played)
              number: '10', // (optional) Valid 32 bit integer specified as string. default: none (Cannot be zero)
              repeatType: 'day', // (Android only) Repeating interval. Could be one of `week`, `day`, `hour`, `minute, `time`. If specified as time, it should be accompanied by one more parameter 'repeatTime` which should the number of milliseconds between each interval
              actions: '["Yes", "No"]',  // (Android only) See the doc for notification actions to know more
          });
    }
}
答案

事实证明,问题是我的Apple开发者帐户需要成为付费订阅者帐户才能使用通知系统。我没有意识到这一点,并且由于某种原因没有得到任何错误。我更新帐户后,通知就开始工作了。

以上是关于React Native Push Notification在XCode控制台中显示,但不在设备上显示的主要内容,如果未能解决你的问题,请参考以下文章

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

重复本地通知在 react-native-push-notification 中不起作用

React Native Push Notification - react-native-fcm - ios无法构建

Typescript React Native navigation.push 输入错误

使用 react-native-push-notification,App 在收到新的 FCM 通知时崩溃

React Native Push Notifications 没有收到通知