Sam*_*ath 4 firebase ionic-framework ionic2 ionic3 angular
我曾尝试使用Firebase本机插件发送推送通知.但它无法正常工作(没有收到真实设备的消息).你能告诉我怎么做吗?
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);
}
});
});
}
Run Code Online (Sandbox Code Playgroud)
完成上述实现后,我尝试使用User Segment
firebase compose消息控制台发送推送通知.
推送通知可能有不同的原因.我提供了一系列步骤来实现推送通知.看看你可能错过了一些东西.
在Ionic app(for android)中实现推送通知的步骤:
注:在火力地堡package name
必须是相同的应用程序id
中
config.xml
.
google-services.json
文件并将其放在应用程序的根目录中.$ ionic platform add android
(如果你还没有)$ 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:+"
}
Run Code Online (Sandbox Code Playgroud)在Android设备上构建您的应用 $ ionic build android
注意: API密钥是Legacy server key
在firebase项目中调用的Cloud Messaging选项卡中找到的密钥.此外,如果您要将通知发送到特定主题,则需要首先使用subscribe方法订阅此主题.
归档时间: |
|
查看次数: |
2827 次 |
最近记录: |