【问题标题】:Why I don't get any push notification on my ionic iOS app?为什么我的 ionic iOS 应用程序没有收到任何推送通知?
【发布时间】:2018-01-18 23:31:29
【问题描述】:

我正在尝试在使用 Ionic 3 开发的应用中实现推送通知。我正在学习本教程:https://medium.com/@ankushaggarwal/generate-apns-certificate-for-ios-push-notifications-85e4a917d522

Android 一切顺利,我收到通知。

但是,在 iOS 上,当我发送推送通知时,在 iOS 上我什么也得不到。

我做了以下事情:

  • 获取 APN 推送证书
  • 已将其上传到我的 Ionic 帐户中
  • 在 Xcode 的“功能”选项卡下打开“推送通知”
  • 还在同一选项卡下打开了“后台模式/远程通知”

我的代码和上面教程中的一样:

initPushNotifications() {
    if (!this.platform.is("cordova")) {
        console.warn("Push notifications not initialized. Cordova is not available - Run in physical device");
        return;
    }

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

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

    pushObject
    .on("registration")
    .subscribe((data: any) => {
        console.log("device token -> " + data.registrationId);

        this.userService.edit({
            ionicToken: data.registrationId
        });
    });

    pushObject.on("notification").subscribe((data: any) => {
        console.log("message -> " + data.message);
        //if user using app and push notification comes
        if (data.additionalData.foreground) {
            // if application open, show popup
            let confirmAlert = this.alertCtrl.create({
                title: "New Notification",
                message: data.message,
                buttons: [{
                    text: 'Ignore',
                    role: 'cancel'
                }, {
                    text: 'View',
                    handler: () => {
                        //TODO: Your logic here
                    }
                }]
            });
            confirmAlert.present();
        } else {
            //if user NOT using app and push notification comes
            //TODO: Your logic on click of push notification directly
            console.log('Push notification clicked');
        }
    });

    pushObject.on('error').subscribe(error => console.error('Error with Push plugin' + error));
}

我还尝试遵循https://docs.ionic.io/services/push/ 的官方文档,它不使用相同的模块。不过,结果是一样的:它适用于 Android,但不适用于 iOS。

我不知道我是否可以在某个地方找到一些日志,以确定是否有错误。如果有人有这方面的信息,请分享。

有人在使用 Ionic 实现推送通知方面取得任何成功吗?

谢谢。

【问题讨论】:

    标签: ios ionic-framework ionic2 ionic3


    【解决方案1】:

    您需要通过 Apple 的 testflight 或 App Store 运行您的应用。根据我的经验,如果您只是在手机上本地运行应用程序,推送通知将不起作用。

    【讨论】:

      猜你喜欢
      • 2020-05-22
      • 1970-01-01
      • 2016-03-22
      • 2023-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多