【发布时间】:2018-03-17 07:13:25
【问题描述】:
我正在使用 NativeScript 的push-plugin 接收通知sent from Firebase Cloud Messaging (FCM):
public constructor(
private _services: PushService,
) {
const settings = {
senderID: "XXXXXXXX",
badge: true,
clearBadge: true,
sound: true,
alert: true,
interactiveSettings: {
actions: [{
identifier: 'READ_IDENTIFIER',
title: 'Read',
activationMode: "foreground",
destructive: false,
authenticationRequired: true,
}, {
identifier: 'CANCEL_IDENTIFIER',
title: 'Cancel',
activationMode: "foreground",
destructive: true,
authenticationRequired: true,
}],
categories: [{
identifier: 'READ_CATEGORY',
actionsForDefaultContext: ['READ_IDENTIFIER', 'CANCEL_IDENTIFIER'],
actionsForMinimalContext: ['READ_IDENTIFIER', 'CANCEL_IDENTIFIER'],
}],
},
notificationCallbackIOS: data => {
console.log("DATA: " + JSON.stringify(data));
},
notificationCallbackAndroid: (message, data, notification) => {
console.log("MESSAGE: " + JSON.stringify(message));
console.log("DATA: " + JSON.stringify(data));
console.log("NOTIFICATION: " + JSON.stringify(notification));
alert(message);
},
};
PushNotifications.register(settings, data => {
console.log("REGISTRATION ID: " + data);
this.toDeviceToken = data;
PushNotifications.onMessageReceived(settings.notificationCallbackAndroid);
}, error => {
console.log(error);
});
}
使用此代码,当我从 Postman 发送它们时,我可以在 notificationCallbackAndroid 方法中收到成功消息。这是我在日志中得到的:
{
"multicast_id": 8382252195536318747,
"success": 1,
"failure": 0,
"canonical_ids": 0,
"results": [
{
"message_id": "0:1521270133609562%161a06bff9fd7ecd"
}
]
}
但是,通知栏中没有显示任何通知。
我们必须使用单独的方法来显示通知吗?
【问题讨论】:
-
我正在尝试通过创建一个新的 IntentService 和 BroadcastReceiver 来实现这一点,如此处所述 - nativescript.org/blog/… 如果您已经实现了相同的功能,请分享信息
标签: firebase push-notification firebase-cloud-messaging nativescript nativescript-angular