Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

notifications called on app start conflicting #185

Open
qwixilver opened this issue Mar 1, 2020 · 1 comment
Open

notifications called on app start conflicting #185

qwixilver opened this issue Mar 1, 2020 · 1 comment

Comments

@qwixilver
Copy link

Hello!

Perhaps I'm not understanding the documentation, or how to use the plugin correctly - if that's the case some extra clarity would be great.

I'm trying to send notifications on a user selectable schedule (either 'hour' or 'day' interval). I've done some testing and found that the only way notifications continue to fire is if I place the notification function in the on-loaded portion of my app-root.js file (the first notification fires regardless of where I put the functions).

Unfortunately, with the function restricted to the app-root, the notifications to fire every time I re-open the app (even if just task switching) which creates a less than desirable user experience.

Is there a way to figure out what schedule the current notification is on (with ID)? or some way to prevent it from firing until the next interval has passed if a user task switches?

I was expecting this to be possible with the getScheduledIds function - but that only seems to give me the ID of what's currently scheduled, but does not provide verbose details such as when the next run is. I don't really see any options to make that useful.

sorry for the n00b question on this one. I've done my best to look through the documentation and code in your repo, as well as the issues here, but I'm still not able to find a solution.

My code for this is (I think anyways) pretty simple:

 if (rootProperties.notificationTimer == "cancel"){
    notifications.cancelAll();
  }
  else{
  notifications.schedule([{
    id:1,
    title:"Sample Notification!",
    interval:rootProperties.notificationTimer, //allows the user to select how frequently they want updates - either hourly or daily.
    body: "This is some long sample notification text that should appear once per interval period...",
    bigTextStyle: true,
    //at: new Date(new Date().getTime() + 10 * 1000)
  }]).then(
      function(scheduledIds) {
        console.log("Notification id(s) scheduled: " + JSON.stringify(scheduledIds));
      },
      function(error) {
        console.log("scheduling error: " + error);
      }
  )
  }

I tried testing with getScheduledIds to see if a notification had already been setup, and if there was one, I simply returned the function. This did stop the notifications from spawning whenever I opened up the app again. Unfortunately it also stopped the recurring scheduled notifications from spawning as well.

Thanks for the help!

@qwixilver
Copy link
Author

So I eventually found that I could simply use the date object to assign each scheduled run to fire at a specific time that would work for me, but this really feels more like a workaround than a solution as it still technically overwrites the previous schedule with a new one each time the app opens, I've just made that invisible to the end user by carefully crafting a date object. it would still be nice if there was some kind of way to modify existing schedules...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant