我在反应原生android上使用FCM进行推送通知但问题是我能够接收通知并且它出现在控制台上但未在设备或模拟器上显示。
我的代码如下
componentDidMount(){
PushNotification.configure({
onRegister: function (token) {
console.log('TOKEN:', token);
},
onNotification: function (notification) {
console.log('NOTIFICATION:', notification);
//I AM ABLE TO SEE THE CONSOLE LOG BUT NOTIFICATION DOESN'T APPEAR ON THE DEVICE
},
senderID: "1062347691026",
permissions: {
alert: true,
badge: true,
sound: true
},
popInitialNotification: true,
requestPermissions: true,
});
}
答案 0 :(得分:0)
Need to create Local Notification then display notification in emulator or android device please use below code inside onNotification method.
var PushNotification = require('react-native-push-notification');
onNotification: function (notification: any) {
const {
foreground,
userInteraction,
message,
id,
data,
...rest
} = notification;
//code for android
if (foreground && !userInteraction) {
PushNotification.localNotification({
...rest,
data,
message,
autoCancel: true,
});
PushNotification.android.setAutoCancel(true);
}
}