我正在使用 NativeScriptpush-plugin
接收从 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);
});
}
使用此代码,notificationCallbackAndroid
当我从 Postman 发送它们时,我可以在方法中接收成功消息。这是我在日志上得到的:
{
"multicast_id": 8382252195536318747,
"success": 1,
"failure": 0,
"canonical_ids": 0,
"results": [
{
"message_id": "0:1521270133609562%161a06bff9fd7ecd"
}
]
}
但是,通知栏中不会显示任何通知。
我们是否必须使用单独的方法来显示通知?