angular – 带有推送通知的Firebase本机插件无效
我曾尝试使用
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相同 >下载google-services.json文件并将其放在应用的根目录中. 注意:您应该在项目中放置google-services.json文件后安装插件 – 因为此文件在安装期间被复制到平台目录中. >安装ionic-native firebase包并实现 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上构建您的应用程序 注意:API密钥是在您的firebase项目中名为Legacy server key的Cloud Messaging选项卡中找到的密钥. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |