推送通知-我可以向模拟器发送消息,但不能在真实设备中发送

时间:2019-07-07 06:05:13

标签: javascript ios react-native react-native-ios

当前,我正在Ios上使用Firebase进行推送通知,但我的应用程序出现了一些问题。

  1. 我可以从服务器接收消息。我正在使用Pushtry测试通知。

enter image description here

但是,当我尝试使用我的真实设备(iPhone 6 Plus,ios 12)时,Pushtry返回了:

  

InvalidApnsCredential

那么,为什么我没有收到来自人体的任何东西(使用模拟器)?我在哪一步做错了(使用真实设备)?我需要检查与认证相关的任何内容吗?

  1. 我想做这样的事情:

    enter image description here

这是我的代码:

async createNotificationListeners() {
  /*
  * Triggered when a particular notification has been received in foreground
  * */
  this.notificationListener = firebase.notifications().onNotification((notification) => {
    const { title, body } = notification;
    console.log('onNotification:');

      const localNotification = new firebase.notifications.Notification({
        show_in_foreground: true,
      })
      .setNotificationId(notification.notificationId)
      .setTitle(notification.title)
      .setBody(notification.body)
      .android.setChannelId('fcm_FirebaseNotifiction_default_channel') // e.g. the id you chose above
      .android.setSmallIcon('@drawable/ic_launcher') // create this icon in Android Studio
      .android.setColor('#000000') // you can set a color here
      .android.setPriority(firebase.notifications.Android.Priority.High)

      firebase.notifications()
        .displayNotification(localNotification)
        .catch(err => console.error(err));
  });

  const channel = new firebase.notifications.Android.Channel('fcm_FirebaseNotifiction_default_channel', 'Demo app name', firebase.notifications.Android.Importance.High)
    .setDescription('Demo app description')
  firebase.notifications().android.createChannel(channel);

  /*
  * If your app is in background, you can listen for when a notification is clicked / tapped / opened as follows:
  * */
  this.notificationOpenedListener = firebase.notifications().onNotificationOpened((notificationOpen) => {
    const { title, body } = notificationOpen.notification;
    console.log('onNotificationOpened:');
    alert(title, body)
  });

  /*
  * If your app is closed, you can check if it was opened by a notification being clicked / tapped / opened as follows:
  * */
  const notificationOpen = await firebase.notifications().getInitialNotification();
  if (notificationOpen) {
    const { title, body } = notificationOpen.notification;
    console.log('getInitialNotification:');
    alert(title, body)
  }
  /*
  * Triggered for data only payload in foreground
  * */
  this.messageListener = firebase.messaging().onMessage((message) => {
    //process data message
    console.log("JSON.stringify:", JSON.stringify(message));
  });
}

我应该采取进一步的措施吗?

0 个答案:

没有答案