Phonegap 在应用程序处于前台时管理通知
Phonegap manage notification when the app is foreground
我正在使用 cordova 和 phonegap 构建移动应用程序。
当通知 reaches.Is 在 cordova 中有任何插件时,我想在设备屏幕上显示一个弹出窗口。
注册、通知和错误这3个事件只有在应用打开时才会被管理。
Registration: the APP registers itself to the push service, receiving
a unique registrationId. This event is useful if you want to store
this value to send notifications to single devices;
Notification: instead of show the classic notification pop up (depending on the
phone), the event notication shows a little pop up (using DevExtreme
feature) to read the message, if the APP is open (if the app is
closed, you will get the notification in the classic way);
Error: if the APP is open and the notification throws some error, here you can manage it.
因此,您必须管理的事件是通知。当应用程序在前台发送通知时会引发此事件(因此,当应用程序 运行)。
在 deviceReady 事件中插入此代码:
var push = PushNotification.init({
android: {
},
ios: {
alert: "true",
badge: "true",
sound: "true",
clearBadge: "true"
},
windows: {}
});
push.on('registration', function (data) {
// data.registrationId
DevExpress.ui.notify("Device registered " + data.registrationId, "success", 3000);
});
push.on('notification', function (data) {
// data.message,
// data.title,
// data.count,
// data.sound,
// data.image,
// data.additionalData
// mostra la notifica se l'app è aperta
DevExpress.ui.notify(data.message, "info", 10000);
});
push.on('error', function (e) {
// e.message
// sarà da togliere, utilissimo in fase di debug
DevExpress.ui.notify(e.message, "error", 10000);
});
并在通知事件中插入您需要的代码。在这种情况下,使用了 DevExtreme,但如果你不使用它,你可以只显示一个 alert or look for what you need (example)enter link description here.
我正在使用 cordova 和 phonegap 构建移动应用程序。 当通知 reaches.Is 在 cordova 中有任何插件时,我想在设备屏幕上显示一个弹出窗口。
注册、通知和错误这3个事件只有在应用打开时才会被管理。
Registration: the APP registers itself to the push service, receiving a unique registrationId. This event is useful if you want to store this value to send notifications to single devices;
Notification: instead of show the classic notification pop up (depending on the phone), the event notication shows a little pop up (using DevExtreme feature) to read the message, if the APP is open (if the app is closed, you will get the notification in the classic way);
Error: if the APP is open and the notification throws some error, here you can manage it.
因此,您必须管理的事件是通知。当应用程序在前台发送通知时会引发此事件(因此,当应用程序 运行)。
在 deviceReady 事件中插入此代码:
var push = PushNotification.init({
android: {
},
ios: {
alert: "true",
badge: "true",
sound: "true",
clearBadge: "true"
},
windows: {}
});
push.on('registration', function (data) {
// data.registrationId
DevExpress.ui.notify("Device registered " + data.registrationId, "success", 3000);
});
push.on('notification', function (data) {
// data.message,
// data.title,
// data.count,
// data.sound,
// data.image,
// data.additionalData
// mostra la notifica se l'app è aperta
DevExpress.ui.notify(data.message, "info", 10000);
});
push.on('error', function (e) {
// e.message
// sarà da togliere, utilissimo in fase di debug
DevExpress.ui.notify(e.message, "error", 10000);
});
并在通知事件中插入您需要的代码。在这种情况下,使用了 DevExtreme,但如果你不使用它,你可以只显示一个 alert or look for what you need (example)enter link description here.