javascript - 将 phonegap-plugin-push 插入 Firebase
问题描述
快点我的环境:Phonegap 8.0.0 phonegap-plugin-push 2.1.2(最后一个版本不兼容phonegap 8.0.0)
当时 :
- 我设法通过phonegap模拟器中的“phonegap push”接收从本地机器生成的推送通知
- 我无法在 phonegap 模拟器中收到来自 Firebase 的推送通知(有可能吗?)
- 当我为 Android 构建应用程序时,由于我的应用程序中的 phonegap-plugin-push 相关代码,她在启动时崩溃(空白页面)(如果我评论它,她会正常启动)
我的代码(VueJS 框架)
console.log('calling push init');
window.gtvapp.push = PushNotification.init({
'android': {
// 'senderID': 'XXXXXXXX'
},
'browser': {},
'ios': {
'sound': true,
'vibration': true,
'badge': true,
'alert': true
// 'senderID': 'xxxxxxxx'
},
'windows': {}
})
console.log('after init')
window.gtvapp.push.on('registration', function(data) {
console.log('registration event: ' + data.registrationId)
var oldRegId = window.localStorage.getItem('registrationId')
if (oldRegId !== data.registrationId) {
window.localStorage.setItem('registrationId', data.registrationId)
// Post registrationId to your app server as the value has changed
// TODO
}
})
window.gtvapp.push.on('error', function(e) {
console.log('push error = ' + e.message)
})
// (...)
let router = this.$router
window.gtvapp.push.on('notification', function(data) {
console.log('notification event')
console.log(JSON.stringify(data))
if (device.platform === 'Android') {
navigator.notification.alert(
data.message, // message
function() {
console.log(window.location.pathname)
console.log(data.additionalData.path)
// window.localStorage.setItem('pushpath', data.additionalData.path)
router.push(data.additionalData.path)
},
data.title,
'En savoir plus'
)
}
})
此代码在模拟器“phonegap serve”+本地推送通知“phonegap push”上完美运行
问题 :
- 第 1 步:理论上是否可以在“phonegap 服务实例”中接收 Firebase 通知
- 第 2 步:只是正确配置 Firebase 注册所需的“google-services.json”文件
非常感谢
解决方案
第 1 步:理论上是否可以在“phonegap 服务实例”中接收 Firebase 通知
不,不是,您必须构建应用程序并在设备上安装 apk
第 2 步:只是正确配置 firebase 注册所需的“google-services.json”文件
是的。就在 phonegap 8 上:
<platform name="android">
<resource-file src="google-services.json" target="app/google-services.json" />
</platform>
“app/”很重要。
推荐阅读
- c# - 如何将此字符串“2020-05-25 15:25:40 EEST”转换为有效的 DateTimeUtc?
- node.js - Mongoose.findOneAndUpdate 无法运行
- python - 将值写入新字段,Python GDAL OGR,不确定如何提交更改,为什么我的字段仍然为空?
- php - 如何在 php 数组中检索工作日的日期?
- python - 使用 Keras 的模型类将 Tensorflow 1.x 代码迁移到 Tensorflow 2.x
- java - 获取二维数组中正方形的平均值
- graphql - 从 Prisma2 的辅助表中获取数据
- javascript - 谷歌折线图日期格式
- javascript - 如何记录仅在 .call() 中使用的函数
- jquery - 将两个带有输入字段的数组合并在一起