awesome_notifications
awesome_notifications copied to clipboard
How to do something, when the scheduled notification is completed?
First of all, I want to thank you for the wonderful package. It really saves a lot of time.
So, to the question:
I have scheduled notifications for a certain list of dates, compiled in this way:
await AwesomeNotifications().createNotification(
content: NotificationContent(
id: newNotificationGeneratedId,
channelKey: 'basic_channel',
title: 'Notification ${title}',
body: '${Emojis.body_flexed_biceps} ${_noteController.text.toString()}',
notificationLayout: NotificationLayout.BigText),
schedule: NotificationCalendar(
day: int.parse(notificationDay),
month: int.parse(notificationMonth),
year: int.parse(notificationYear),
hour: int.parse(displayTimeHour),
minute: int.parse(displayTimeMinute),
second: 0,
millisecond: 0,
repeats: false,
),
actionButtons: [
NotificationActionButton(
key: 'open_app',
label: 'Open App',
),
],
);
How to do something, when the scheduled notification is completed? Ex, run function or something like that?
Thanks.
It's not possible to execute any code when the schedule is completed, specially on iOS. To do it, I recommend you to use WorkManager.
he may be means displayedStream: in my case I had some reminders that schedules notifications. when scheduled time comes : displayedStrem event fires even if notification is not shown on screen for some reasons (but it was created for sure).
This can happen if the notification was displayed before. The displayStream stores the call and fires it as soon as possible.
@rafaelsetragni I need to perform some action when a scheduled notification is displayed, regardless the app is running or terminated. Is it possible to achieve with this package or work manager? I guess I'll have to use both in combination but not sure how. Your help is much appreciated. Thanks.
At same time when terminated is not possible with awesome. It runs as soon as possible when the app is reopened. You can see all the combinations here.
Yup I already saw those combinations. My question was that could work manager help in this situation because it looks like work manager can't execute code at exact scheduled time.
No, workmanager doesn't work this way. It runs in random periods, with minimum of 15 minutes between each one. And unfortunately, there is no way to workaround it on iOS. You cannot ensure any execution at specific time if your app is not on foreground.
Hmm...so its impossible to update my home screen widget extensions when scheduled notification is displayed. Thanks for clarifying.
That's the point. What you're desiring as final result is totally possible with awesome. Just the way that you're thinking on how to do is not needed. You can use displayedStream and execute any other action, including personalize your home screen as soon as the user reopened the app.
Yes I knew that but the aim is to update widget data on notification generation, not app opening, because the user may or may not click the notification to open the app. Thanks again for your help. Appreciated.
Hi! Sorry for taking so long to respond to your issue on GitHub. I was focused on releasing the new 0.7.0 version of awesome_notifications and awesome_notifications_fcm and i didn't had time enough to do both. But now I can answer all your questions.
So now i'm asking you to recreate this topic using the new issue template. There's a lot of missing informations that i need to understand your problem, and all the instructions are already in the new issue template. Also, remember to check beforehand if your issue was posted by another user.
So I will automatically close all previous issues so far. Sorry for the inconvenience and i will be waiting for your new issue request.
Thank you so much for your support!