Push Notification - я могу отправить сообщение в эмулятор, но не в реальном устройстве - PullRequest
2 голосов
/ 07 июля 2019

В настоящее время я делаю push-уведомления с использованием Firebase на Ios и у меня возникли проблемы с моим приложением.

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

Есть ли какой-нибудь дальнейший шаг, которому я должен следовать?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...