【发布时间】:2021-07-15 03:46:57
【问题描述】:
通知不在模拟器上显示,而是在物理设备上。我仍然可以听到设备的声音。
useEffect(() => {
PushNotification.createChannel(
{
channelId: "fcm_fallback_notification_channel", // (required)
channelName: "My channel", // (required)
channelDescription: "A channel to categorise your notifications", // (optional) default: undefined.
playSound: false, // (optional) default: true
soundName: "default", // (optional) See `soundName` parameter of `localNotification` function
importance: Importance.HIGH, // (optional) default: Importance.HIGH. Int value of the Android notification importance
vibrate: true, // (optional) default: true. Creates the default vibration patten if true.
},
(created) => console.log(`createChannel returned '${created}'`) // (optional) callback returns whether the channel was created, false means it already existed.
);
PushNotification.channelExists('fcm_fallback_notification_channel', function (exists) {
console.log(exists); // true/false
});
PushNotification.getChannels(function (channel_ids) {
console.log(channel_ids); // ['channel_id_1']
});
const unsubscribe = messaging().onMessage(async (remoteMessage) => {
console.log('A new FCM message arrived!', JSON.stringify(remoteMessage));
PushNotification.localNotification({
title: remoteMessage.notification.title,
message: remoteMessage.notification.body,
vibrate: true,
vibration: 300,
playSound: true,
soundName: 'default',
actions: ["Yes", "No"],
channelId:"fcm_fallback_notification_channel"
})
});
return unsubscribe;
}, []);
这是显示通知的代码。我也得到了 console.log()
【问题讨论】:
标签: android react-native react-native-android react-native-firebase react-native-push-notification