【问题标题】:How get push notification in real time with Framework7 Cordova如何使用 Framework7 Cordova 实时获取推送通知
【发布时间】:2020-08-31 21:07:37
【问题描述】:
我正在使用框架 7 开发一个 Android 混合移动应用程序,除了推送通知之外,我几乎做到了。现在,我不知道如何在framework7中添加推送通知。
之前,我开发了很多 PhoneGap 应用程序,我经常使用 PhoneGap 插件添加 phonegap-plugin-push,这对我来说就像一个魅力。
但我的运气不好,它不适用于 framework7。 (http://framework7.io/)
请指导我添加实时通知。
【问题讨论】:
标签:
cordova
html-framework-7
【解决方案1】:
我通过使用 Cordova-push-plugin 解决了我的问题。
这是代码。
var myApp = new Framework7({
modalTitle: "VDST",
// Enable Material theme
material: true,
});
myApp.push = PushNotification.init({
"android": {
"senderID": "xxxxxxxxxx"
}, "ios": {
"sound": true,
"vibration": true,
"badge": true
},
"windows": {}
});
myApp.push.on('registration', function(data) {
var oldRegId = localStorage.getItem('registrationId');
if (oldRegId !== data.registrationId) {
localStorage.setItem('registrationId', data.registrationId);
var token=data.registrationId;
myApp.alert(token);
}
});
myApp.push.on('error', function(e) {
console.log("push error = " + e.message);
});
myApp.push.on('notification', function(data) {
console.log('notification event');
var cards = document.getElementById("cards");
var push = '<div class="row">' +
'<div class="col s12 m6">' +
'<div class="card darken-1">' +
'<div class="card-content black-text">' +
'<span class="card-title black-text">' + data.title + '</span>' +
' <p>' + data.message + '</p>' +
' <p>' + data.additionalData.foreground + '</p>' +
' </div>' +
' </div>' +
' </div>' +
'</div>';
cards.innerHTML += push;
});
这里是完整的参考:
http://macdonst.github.io/push-workshop/index.html