【问题标题】:Ionic 3 Push Notification Topic SubscriptionIonic 3 推送通知主题订阅
【发布时间】:2017-11-26 00:56:06
【问题描述】:

我有以下代码用于使用 ionic cloud 和 Firebase Cloud Messaging 进行推送通知。

let topic = "topics/" + this.user.userRole + "/" + this.user.location;

const options:PushOptions = {
    android: {
        senderID: "XXXXX",
        sound: true,
        vibrate: true,
        //topics: [topic]
    },
    ios: {
        alert: "true",
        badge: false,
        sound: "true"
    },
    windows: {}
};

它可以工作,但是一旦我尝试订阅特定主题,应用程序就会在从 android 运行时崩溃。

当我使用订阅时,按以下方式:

pushObject.on('registration').subscribe((data:any) => {
    console.log("device registered -> ", data);
    this.saveToken(data.registrationId);
    let topic = "topics/" + this.user.userRole + "/" + this.user.location;
    pushObject.subscribe(topic).then((res:any) => {
        console.log("subscribed to topic: ", res);
    });
});

同样,什么也没发生,我也没有收到任何信息表明我能够订阅某个主题。

如何完成主题订阅?

【问题讨论】:

    标签: firebase ionic-framework push-notification


    【解决方案1】:

    我在 android studio 中打开项目并从那里运行它,而不是使用 ionic-cli。 我看到有关无效主题名称的 IllegalArgumentException。 这个answer 帮助我解决了关于主题名称中可接受字符的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-14
      • 2015-06-19
      • 2021-10-16
      • 1970-01-01
      • 1970-01-01
      • 2019-09-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多