question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Random message for scheduled local notifications

See original GitHub issue

Question

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:closed
  • Created 2 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
wojniemieccommented, Jun 10, 2021

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.

1reaction
Dallas62commented, May 30, 2021

Hi, You can schedule multiple notifications with a differents messages. Regards

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found