在iOS上使用Ionic和Firebase推送通知



我已经使用这些说明在iOS上使用Firebase设置推送通知。我很确定我已经正确设置了所有Apple证书,并且可以很好地从FCM(Firebase Cloud Messaging(发送通知,并且状态为"已发送",但它们从未到达我的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));
  }

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

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

“AppDelegate+FCM”

在哪里可以找到以下方法: customDidFinishingLaunchingWithOptions

请替换以下:

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

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

相关内容

  • 没有找到相关文章

最新更新