Please I would love you all to assist me solve this bug I've been on since last night with react-native-push-notification.
I've been trying to send a push notification using the PushNotification.localNotificationSchedule() function. The code works perfectly until I add the id attribute to the notification object.
Here's an example of when the code works:
PushNotification.localNotificationSchedule({
channelId: "channel-id",
title: `Hi there ${fullName}!`,
message: `You've Got A To-Do "${todoInfo.title}" Now!`,
date: new Date(todoInfo.dateDue),
allowWhileIdle: true,
});
It also works when I do this:
PushNotification.localNotificationSchedule({
channelId: "channel-id",
title: `Hi there ${fullName}!`,
message: `You've Got A To-Do "${todoInfo.title}" Now!`,
date: new Date(todoInfo.dateDue),
id: 555,
allowWhileIdle: true,
});
But doesn't work when I use a library to generate a unique id so that I can cancel the notification afterwards; example code here:
import 'react-native-get-random-values';
import { v4 as uuidv4 } from 'uuid';
// Some other code here
PushNotification.localNotificationSchedule({
channelId: "channel-id",
title: `Hi there ${fullName}!`,
message: `You've Got A To-Do "${todoInfo.title}" Now!`,
date: new Date(todoInfo.dateDue),
id: uuidv4(),
allowWhileIdle: true,
});
Please, is there a way I can get past this?
I tried using a random id generator like uuid and it didn't work. When I pass the id hardcoded, it works. I'm expecting a notification to show up on my app.
As per the documentation, the notification won't work until the Channel is created:
"channel-id"is the default createdchannelIdand therefore notifications work when using it in thechannelIdCreate a local Channel ID:
you have to hard code the notification channel ID in AndroidMainfest.xml
For remote Firebase Cloud Messenger Notifications refer to FCM documentation
Checking Channel Exists & Listing them
Here is the code from the documentation to check for channels & list out the available channels for notifications