【问题标题】:FCM Push Notification are not working in IOS using Ionic Capacitor使用离子电容器的 FCM 推送通知在 IOS 中不起作用
【发布时间】:2021-11-02 09:19:45
【问题描述】:

使用 CAPACITORIONIC 在 Android 上一切正常,但在 IOS 中出现以下错误:

在检索发件人 ID“mySenderId”的 FCM 令牌之前未设置 APNS 设备令牌。此 FCM 令牌的通知将不会通过 APNS 传递。请确保在设置 APNS 设备令牌后重新检索 FCM 令牌。

????   Capacitor Doctor  ???? 

Latest Dependencies:

  @capacitor/cli: 3.2.2
  @capacitor/core: 3.2.2
  @capacitor/android: 3.2.2
  @capacitor/ios: 3.2.2

Installed Dependencies:

  @capacitor/cli: 3.2.2
  @capacitor/core: 3.2.2
  @capacitor/android: 3.2.2
  @capacitor/ios: 3.2.2

我可以在我的Xcode 日志中看到 FCM 令牌,但通知不起作用。

参考资料:

My Issue

Simmilar Issue

【问题讨论】:

    标签: ios firebase ionic-framework firebase-cloud-messaging capacitor


    【解决方案1】:

    解决办法是在FCM token之前注册APNS token。

     PushNotifications.requestPermissions().then((permission) => {
        if (permission.receive == "granted") {
          // Register with Apple / Google to receive push via APNS/FCM
          if(Capacitor.getPlatform() == 'ios'){
            PushNotifications.register().then((res)=>{
              console.log('From Regisiter Promise', res)
            })
            PushNotifications.addListener('registration', (token: Token)=>{            
              FCM.getToken().then((result) => {
                this.remoteToken = result.token;
              }).catch((err) => console.log('i am Error' , err));
            })
          }else{
            FCM.getToken().then((result) => {
              this.remoteToken = result.token;
            }).catch((err) => console.log('i am Error' , err));
          }
        } else {
          // No permission for push granted
          alert('No Permission for Notifications!')
        }
      });
    

    对于最新版本的插件:

    PushNotifications.requestPermissions().then((permission) => {
            if (permission.receive == "granted") {
    
              PushNotifications.addListener('registration', async ({ value }) => {
                let token = value // Push token for Android
              
                // Get FCM token instead the APN one returned by Capacitor
                if (Capacitor.getPlatform() === 'ios') {
                  const { token: fcm_token } = await FCM.getToken()
                  token = fcm_token
                }
                // Work with FCM_TOKEN
                
                console.log(token);
              })
            } else {
              // No permission for push granted
              alert('No Permission for Notifications!')
            }
          });
    

    【讨论】:

    【解决方案2】:

    您似乎缺少 APNS 设置并将其与 FCM 连接。只需按照这个很棒的教程: https://devdactic.com/push-notifications-ionic-capacitor/

    【讨论】:

    • 我确实按照相同的教程来集成推送通知。
    猜你喜欢
    • 2018-02-14
    • 2018-04-24
    • 2018-03-05
    • 2021-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-14
    • 1970-01-01
    相关资源
    最近更新 更多