加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angular – 带有推送通知的Firebase本机插件无效

发布时间:2020-12-17 17:33:12 所属栏目:安全 来源:网络整理
导读:我曾尝试使用 Firebase native plugin 发送推送通知.但它无法正常工作(没有收到真实设备的消息).你能告诉我怎么做吗? app.component.ts constructor(platform: Platform,private firebase: Firebase) { platform.ready().then(() = { this.firebase.getToke
我曾尝试使用 Firebase native plugin发送推送通知.但它无法正常工作(没有收到真实设备的消息).你能告诉我怎么做吗?

app.component.ts

constructor(platform: Platform,private firebase: Firebase) {

    platform.ready().then(() => {
        this.firebase.getToken()
            .then(token => console.log(`The token is ${token}`)) // save the token server-side and use it to push notifications to this device
            .catch(error => console.error('Error getting token',error));

 this.firebase.onNotificationOpen()
            .subscribe(res => {
                if (res.tap) {
                    // background mode
                    console.log("background");
                    console.log(res);
                    alert(res);
                } else if (!res.tap) {
                    // foreground mode
                    console.log("foreground");
                    console.log(res);
                    alert(res);
                }
            });

      });
}

在上面的实现之后,我尝试使用firebase撰写消息控制台上的用户段发送推送通知.

解决方法

推送通知可能有不同的原因.我提供了一系列步骤来实现推送通知.看看你可能错过了一些东西.

在Ionic app(for android)中实现推送通知的步骤:

>创建一个新的firebase project

注意:Firebase软件包名称必须与.中的应用程序ID相同
config.xml中.

>下载google-services.json文件并将其放在应用的根目录中.
>添加android平台$ionic platform add android(如果你还没有)
>安装firebase插件$ionic plugin add cordova-plugin-firebase.

注意:您应该在项目中放置google-services.json文件后安装插件 – 因为此文件在安装期间被复制到平台目录中.

>安装ionic-native firebase包并实现onNotificationOpen方法.
>将以下内容添加到build.gradle文件中:

buildscript {
// ...
    dependencies {
        // ...
        classpath 'com.google.gms:google-services:3.1.0'
    }
}

//....

dependencies {
    // SUB-PROJECT DEPENDENCIES START
    // ...
    compile "com.google.firebase:firebase-core:+"
    compile "com.google.firebase:firebase-messaging:+"
}

>在Android设备$ionic build android上构建您的应用程序
>测试推送通知.您可以使用this免费的firebase通知发件人.

注意:API密钥是在您的firebase项目中名为Legacy server key的Cloud Messaging选项卡中找到的密钥.
此外,如果您要将通知发送到特定主题,则需要先使用subscribe方法订阅此主题.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读