firebase - ionic - firebase push only work with opened app?
问题描述
I've implemented FireBaseX in my Ionic 4 app to send remote notifications.
this.platform.ready().then(() => {
let platforms = this.platform.platforms();
if(platforms.includes('ios') || platforms.includes('android') || platforms.includes('mobile')){
this.firebase.getToken().then(token => {
console.log(`FIREBASE TOKEN ${token}`);
if(platforms.includes('ios')) this.firebase.grantPermission();
});
this.firebase.onMessageReceived().subscribe(data => {
console.log('FIREBASE MESSAGE', data);
});
}
});
So when I open the app in iOS, it asks for permissions correctly.
Then I send test message and the console.log() appears correctly.
2020-02-05 17:35:38.282123-0300 Parkaz[86464:2354851] didReceiveMessage: {
"collapse_key" = "com.myapp.app";
from = 678323471xxxx;
notification = {
body = teste;
e = 1;
tag = "campaign_collapse_key_5659280550157990837";
title = teste;
};
}
However, if the app is not opened, nothing happens. The notification banner doesn't appear, no badge, no sound... nothing...
Am I doing something wrong?
解决方案
您可以使用邮递员测试您的通知。
POST : https://fcm.googleapis.com/fcm/send
标题
Content-Type:application/json
Authorization:key=AIzaXXXXXXXXXX
身体
安卓
{
"notification": {
"title": "Your Notification Title",
"body": "This is Message",
},
"to" : FIREBASE TOKEN,
"data": {
"content-available": 1,
"foreground": false,
"clickAction": "/chat"
}
}
iOS
{
"to" : FIREBASE TOKEN,
"data": {
"title": "Your Notification Title",
"body": "This is Message",
"content-available": 1,
"foreground": false,
}
}
推荐阅读
- angular - Angular 7 - 使用路由的步进器组件
- bash - Correct format for a command in Codenvy
- r - 在 ggplot 区域外添加文本
- amazon-web-services - 使用亚马逊信任服务证书
- python - How to keep variable value if new value is None
- android-room - How to order items from Room database by date with "MMM dd yyyy" format
- javascript - ReactJS - How to have a string with multiple colors for each characters
- swift - didSelectRowAt:IndexPath 不起作用,并且在按下单元格时不会打印到控制台
- docusignapi - TSP 签名哈希会话信息
- java - Sorting a List of integers based on a List of strings in Java