Random message for scheduled local notifications
See original GitHub issueQuestion
Is there a way to show a different message every time for scheduled local notifications?
I have a set of messages stored in an array and I would like to show any one of them every time a notification is triggered.
I’ve tried this
const messages = [...];
function getRandom() {
return Math.floor(Math.random() * (10);
}
PushNotification.localNotificationSchedule({
//... You can use all the options from localNotifications
channelId: "my-channel",
message: messages[getRandom()], // (required)
date: new Date(Date.now() + 60 * 1000), // in 60 secs
});
But this calls the same message every time.
I think this does not work because PushNotification.localNotificationSchedule
is called only once.
Is there a way to achieve this ?
Issue Analytics
- State:
- Created 2 years ago
- Comments:7
Top Results From Across the Web
Choose random text and set it in alert for local notification?
Choose random text and set it in alert for local notification? ... For each category user can choose multiple time and set the...
Read more >Scheduling local notifications - a free Hacking with iOS
Notifications can take a variety of forms, but the most common thing to do is ask for permission to show alerts, badges, and...
Read more >How to send local notification daily at random time?
i have stored these tips locally.i want to send local push notification of these tips.i want to send push notification randomly with random...
Read more >Scheduling Local Notifications (Swift 5) | by Batuhan Gobekli
Notifications can take several forms, but the most common thing to do is to request permission to view notices, badges, and sounds, which...
Read more >Automated Messages - OneSignal Documentation
. Scheduled Recurring Notifications · The OneSignal Create Notification API · Integrately | OneSignal integration or Zapier | OneSignal · Scheduling your ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This doesn’t solve the problem, if I want to schedule a notification once a day with random message, do I need to schedule new notification every day? I would like to have an option to set a “messageFn” that would be evaluated just before sending scheduled local notification. Is that possible or is there a good workaround for that?
Edit. What could work is to support handling message/title values as array of strings and choose random element from that array each time notification is being sent.
Hi, You can schedule multiple notifications with a differents messages. Regards