【问题标题】:Push notifications with Ionic and Firebase on iOS在 iOS 上使用 Ionic 和 Firebase 推送通知
【发布时间】:2017-11-17 07:28:20
【问题描述】:

我已按照这些说明在 iOS 上使用 Firebase 设置推送通知。我很确定我已经正确设置了所有 Apple 证书,并且可以很好地从 FCM(Firebase 云消息传递)发送通知,并且状态为“已发送”,但它们从未到达我的 iPhone。

https://ionicframework.com/docs/native/push/

这是我的代码。任何建议为什么这不起作用或如何调试它将不胜感激!非常感谢!

import { Push, PushObject, PushOptions } from '@ionic-native/push';

constructor(platform: Platform, private push: Push, public alertCtrl: AlertController) {
    platform.ready().then(() => {
      StatusBar.styleDefault();
      Splashscreen.hide();
      this.pushNotifications();
    });
  }
  pushNotifications() {
    this.push.hasPermission().then((res: any) => {
      if (res.isEnabled) { console.log('We have permission to send push notifications');}
      else { console.log('We do NOT have permission to send push notifications'); }
    }).catch((error) => { console.log("Push Notification needs Cordova: " + JSON.stringify(error));});

    const options: PushOptions = {
      android: {
        senderID: 'My_ID'
      },
      ios: {
        alert: 'true',
        badge: true,
        sound: 'false'
      },
      windows: {}
    };

    const pushObject: PushObject = this.push.init(options);

    pushObject.on('notification').subscribe((notification: any) => {
      if(notification.additionalData.foreground) {
        let youralert = this.alertCtrl.create({
          title: 'New Push notification',
          message: notification.message
        });
        youralert.present();
      }
    });

    pushObject.on('registration').subscribe((registration: any) => console.log('Device registered', JSON.stringify(registration)));
    pushObject.on('error').subscribe(error => console.error('Error with Push plugin', error));
  }

【问题讨论】:

  • 您是否尝试将有效负载priority 设置为high
  • @AL。我该怎么做?谢谢!
  • 它实际上是在 Firebase 中默认设置的。所以不,不幸的是,这无济于事。
  • 我对原生推送插件有类似的问题。然后我迁移到 ionic-native fcm 插件 (ionicframework.com/docs/native/fcm)。这个 fcm 插件可以正常工作。

标签: ios firebase push-notification ionic2 firebase-cloud-messaging


【解决方案1】:

您是否尝试过从在线 apns 测试工具发送推送通知? (例如。http://pushtry.com/)。如果您仍然有同样的问题,请再次检查您的 ios 证书、配置和设备检查。

【讨论】:

    【解决方案2】:

    您应该在链接中添加 FCM 插件: https://ionicframework.com/docs/native/fcm/

    然后在插件中找到以下文件:

    “AppDelegate+FCM”
    

    您可以在哪里找到以下方法: customDidFinishLaunchingWithOptions

    请在下面替换:

    [FIRApp configure];
    
        with this
    
     // [START configure_firebase]
        if(![FIRApp defaultApp]){
            [FIRApp configure];
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-11
      • 1970-01-01
      • 2017-02-05
      • 2018-06-18
      • 2018-12-25
      • 1970-01-01
      • 2019-01-30
      相关资源
      最近更新 更多