【发布时间】:2021-02-18 14:50:09
【问题描述】:
我正在处理 IONIC 和 FCM 的问题。如下所示,我正在从 Node JS 中的服务器向 IONIC 中的应用程序发送“数据”而不是“通知”,我在控制台中看到数据已发送,但我不知道如何访问它,根据对于文档,它在 Intent extras 中,但我没有成功。我可以使用也为我服务的“通知”,但问题在于,只有当您单击推送通知时,您才能获得数据……因此,如果客户端没有单击通知并从后台将无法获取该数据...
我在 Node 中的服务器:
const options = {
priority: "high",
timeToLive: 60 * 60 * 24,
};
const message_notification = {
/*
notification: {
title: "¡Tienes un nuevo pedido!",
body: "Tienes 30 segundos para aceptar el pedido, de lo contrario será rechazado.",
sound: "default",
vibrate: 1,
Badge: 1,
click_action: "FCM_PLUGIN_ACTIVITY"
},
*/
data: {
detalles: JSON.stringify(nuevopedido)
},
};
admin
.messaging()
.sendToDevice(primeroCola.socket_id, message_notification, options)
.then((response) => {
console.log("Notificación enviada", response);
})
.catch((error) => {
console.log(error);
});
我在 ionic 中的应用:
this.fcm.onNotification().subscribe((data) => {
console.log(JSON.parse(data.detalles))
});
我在 Ionic 中尝试了 Cordova Intent Web 插件,但我无法获得 FCM Intent,只是我在 Ionic 中的项目,我对 Android 不太了解。
WebIntent.getIntent().then((intent) => {
console.log('Action' + JSON.stringify(intent.action));
const intentExtras = intent.extras;
if (intentExtras == null) {
console.log("No hay extras")
} else {
console.log('Extras de intent: ' + JSON.stringify(intentExtras));
}
}, (error) => {
console.log('Error getting launch intent', error);
});
【问题讨论】:
标签: android ionic-framework firebase-cloud-messaging