我无法在 React Native 中收到最新 android 版本(>6)的推送通知
I'm unable to receive the push notification in latest android version(>6) in react native
我尝试了所有解决方案,但我无法在任何设备(无论是模拟器还是任何真实设备)中使用 android 版本大于 6(Marshmallo) 的 package 获得推送通知。
我在浪费了很多时间后自己找到了这个问题的答案,
在 android 版本 7 或低于 7 的情况下,推送通知将照常工作,但在 android 版本大于 7 的情况下,必须为推送通知提供频道 ID在下面的例子中
PushNotification.createChannel(
{
channelId: "your_unique_channel_id", // (required)
channelName: "your_channel_name", // (required)
channelDescription: "A channel to categorise your notifications", // (optional) default: undefined.
soundName: "default", // (optional) See `soundName` parameter of `localNotification` function
importance: 1, // (optional) default: 4. 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.
);
首先在App启动时设置频道Id,然后在设置日程或推送通知时传递Id,像这样
PushNotification.localNotificationSchedule({
channelId:"your_unique_channel_id", //same as passed while setting up the at time of creating channel
autoCancel: true,
title: "TITLE",
message: "MESSAGE",
vibrate: false,
vibration: 300,
playSound: true,
soundName: 'default'
date: new Date(),
})
在此之后,我将能够在每个设备上为我的 React 本机应用程序获取推送通知
我尝试了所有解决方案,但我无法在任何设备(无论是模拟器还是任何真实设备)中使用 android 版本大于 6(Marshmallo) 的 package 获得推送通知。
我在浪费了很多时间后自己找到了这个问题的答案,
在 android 版本 7 或低于 7 的情况下,推送通知将照常工作,但在 android 版本大于 7 的情况下,必须为推送通知提供频道 ID在下面的例子中
PushNotification.createChannel(
{
channelId: "your_unique_channel_id", // (required)
channelName: "your_channel_name", // (required)
channelDescription: "A channel to categorise your notifications", // (optional) default: undefined.
soundName: "default", // (optional) See `soundName` parameter of `localNotification` function
importance: 1, // (optional) default: 4. 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.
);
首先在App启动时设置频道Id,然后在设置日程或推送通知时传递Id,像这样
PushNotification.localNotificationSchedule({
channelId:"your_unique_channel_id", //same as passed while setting up the at time of creating channel
autoCancel: true,
title: "TITLE",
message: "MESSAGE",
vibrate: false,
vibration: 300,
playSound: true,
soundName: 'default'
date: new Date(),
})
在此之后,我将能够在每个设备上为我的 React 本机应用程序获取推送通知