firebase - ionic 3 - 在 Ionic 上接收推送通知不起作用
问题描述
有人在 ionic 3 上处理过通知吗?我正在尝试创建一些存储 fcm 通知的应用程序,我正在尝试大多数教程,但似乎没有任何效果。当我收到通知并点击它时,我无法收到消息。
这是我尝试过的一些代码
initializeApp() {
this.platform.ready().then(() => {
// START
this.fcm.getToken().then(token => {
console.log(token);
alert('token: '+token);
});
this.fcm.onTokenRefresh().subscribe(token => {
console.log(token);
alert('refresh token: '+token);
});
this.fcm.onNotification().subscribe(data => {
alert('data: '+data);
if(data.wasTapped){
console.log("Received in background " + JSON.stringify(data) );
alert("Received in background " + JSON.stringify(data) );
this.nav.setRoot(InboxnotifPage, {data: data});
} else {
console.log("Received in foreground" + JSON.stringify(data) );
alert("Received in foreground" + JSON.stringify(data) );
this.nav.push(InboxnotifPage, {data: data});
};
});
// END
}
}
解决方案
您必须在项目构建根目录中添加 .plist 文件才能与您的设备通信
this.fcm.onNotification().subscribe(data => {
if (data.wasTapped) {
alert('');
} else {
console.log("Received in foreground");
// this.presentToast("Received in foreground");
}
});
this.getToken();
this.fcm.onTokenRefresh().subscribe(token => {
this.rest.globalToken = token;
});
});
遵循原始文档,请首先检查来自https://console.firebase.google.com的通知,然后将令牌传递给 rest Api
推荐阅读
- asp.net-core - 如何通过在 Dapper 中执行 SQL 查询返回字符串
- html - 为什么 .class-name-1.class-name-2:first-child 不起作用?
- php - PHP 使用 JOINS 显示来自 MySQL 的数据
- apache2 - 如何访问logstash过滤步骤中的嵌套字段?
- docker - Kubernetes DNSPolicy 配置
- java - Java 给出看似随机的 StackOverflowError
- ios - 一个应用程序 -> 多种语言
- typescript - 如何在我的自定义类型定义文件中导入其他类型定义
- reactjs - 使用 redux-tooltip 时“this.props.dispatch 不是函数”
- c++ - 为什么不能前向声明 typedef?