将 phonegap-plugin-push 插入 Firebase
plug phonegap-plugin-push to 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 serve instance"
中接收 Firebase 通知
- 第 2 步:只是 "google-services.json" 正确配置 firebase 注册所需的文件
非常感谢
第 1 步:理论上是否可以在 "phonegap serve instance"
中接收 Firebase 通知
No it’s not, you have to build the app and install the apk on the device
第 2 步:只是 "google-services.json" 正确配置 firebase 注册所需的文件
Yes.
Just on thing for phonegap 8 :
<platform name="android">
<resource-file src="google-services.json" target="app/google-services.json" />
</platform>
"app/"很重要。
快点我的环境: 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 serve instance" 中接收 Firebase 通知
- 第 2 步:只是 "google-services.json" 正确配置 firebase 注册所需的文件
非常感谢
第 1 步:理论上是否可以在 "phonegap serve instance"
中接收 Firebase 通知No it’s not, you have to build the app and install the apk on the device
第 2 步:只是 "google-services.json" 正确配置 firebase 注册所需的文件
Yes. Just on thing for phonegap 8 :
<platform name="android">
<resource-file src="google-services.json" target="app/google-services.json" />
</platform>
"app/"很重要。