如何使用 Framework7 Cordova 实时获取推送通知
How get push notification in real time with Framework7 Cordova
我正在使用框架 7 开发一个 Android 混合移动应用程序,除了推送通知,我几乎做到了。现在不知道怎么在framework7中添加推送通知
之前,我开发了很多 PhoneGap 应用程序,我经常使用 PhoneGap 插件添加 phonegap-plugin-push,这对我来说就像一个魅力。
但我运气不好,它不能与 framework7 一起使用。 (http://framework7.io/)
请指导我添加实时通知。
我使用 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;
});
这里是完整的参考:
我正在使用框架 7 开发一个 Android 混合移动应用程序,除了推送通知,我几乎做到了。现在不知道怎么在framework7中添加推送通知
之前,我开发了很多 PhoneGap 应用程序,我经常使用 PhoneGap 插件添加 phonegap-plugin-push,这对我来说就像一个魅力。
但我运气不好,它不能与 framework7 一起使用。 (http://framework7.io/)
请指导我添加实时通知。
我使用 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;
});
这里是完整的参考: