I am using flutter_local_notifications plugin to schedule notifications, but I want to achieve two things.
The scheduled notification should run some code every time, before showing the notification to check whether or not to display the notification.
I want to specify a custom time interval, instead of the options given by RepeatInterval
Related
I have created a local notification on 10:00 AM and I want to repeat the notification based on a calculation for the next time when the first notification triggered.
So how can I listen to the notification trigger to create the next notification?
Note: I have used didRecieve notification delegate but it works only if the app in the foreground I want the same thing for the background.
time interval trigger would do it.
https://developer.apple.com/documentation/usernotifications/untimeintervalnotificationtrigger
Use a UNTimeIntervalNotificationTrigger object for local notifications that you want delivered at a time relative to the current time. You specify the number of seconds that must elapse before the notification fires. You can also set up the trigger to repeat at the specified interval.
Is there any way to know if a local notification has been delivered so that I can change UI based on it.
For example, time and date is shown when the task is scheduled. If the notification is delivered; i want it to say ‘Time’s up’
How do I add a repeated notification that’s starts at a certain time?
Regarding to the documentation
a notification trigger is either scheduled for an absolute calendar date/time using UNCalendarNotificationTrigger or repeated using a UNTimeIntervalNotificationTrigger.
Is there a way schedule a mix of both types?
I'm making an app, reminding user to do smth each day, and I can't implement the situation , when notifications are shown or not shown depending on some condition even if the app is in background mode.
one possible variant is to set endless repeating notifications:
notification.repeatInterval = NSCalendarUnit.NSDayCalendarUnit
but then some method is required to skip notification for present day if some condition was satisfied. If one removes these notifications from Notification Center they won't fire next day.
The other way is to make some method creating notification only for present day, and then removing them if some condition is satisfied. The problem is, this method should create these scheduled notification even being in background mode, and I have no idea how to make that.
Are there any ideas?
Unfortunately the only way you can wake up your app at a specific time is through a silent APNS push. This means you need a server that will send silent pushes to your device, the user needs to have internet and the user needs to opt out for push.
Maybe background fetch will work for you ? With Background Fetch your app gets woken up every minimum interval. You could set your app to wake up every x minutes and check that condition.
[application setMinimumBackgroundFetchInterval:100]; //seconds
Please beware that:
The minimum number of seconds that must elapse before another
background fetch can be initiated. This value is advisory only and
does not indicate the exact amount of time expected between fetch
operations.
I understand that you cannot modify a UILocalNotification after it has been scheduled. My problem is that I want to set the .repeatInterval so that it fires at a specific time once per day. However I want the content to change every day. So the user sets the alarm to fire at 10AM, and every day at 10AM gets an alert with different content without having to reset their alarm.
I was thinking about canceling and rescheduling when didReceiveLocalNotification was called but that requires the user to launch the app before the next scheduled alert. Is there a way to call a method immediately after the alert is fired?
Unfortunately you have no certain way of knowing that a local notification has fired unless your app is frontmost at the time it fires.
And, as you say, you cannot change a notification.
So I think your best bet is do not use repeating notifications. Set up a different single notification for each day, say, two weeks ahead, with different messages for each, and hope the user runs the app between now and then so that you can "refresh" the queue, as it were. Maybe make only the last one repeating, just in case, so that the notifications never stop - but of course then the message will be same each time. But there's nothing you can do about that. You can't force the user to run the app.