I have a UILocalNotification that repeats every hour and I would like to change the message when it repeats so it is different, or rotates between 3 messages.
Does anyone know of a way to do this?
Also, it appears I cannot customize my repeating local notifications beyond once every minute, hour, day, etc. What I'd like is a notification every 15 minutes. I suspect that can't be done though... unless you know a way?
Many thanks for assistance you can offer.
If you wanna change the message you can acces to the scheduledLocalNotifications array in your app delegate and modify the message, but to do that you need the app to be running. I think it's better to simply schedule different notifications with the different messages you want to show.
About the repeating interval the simple answers is no, you can't create your own repeating intervals. This is one of the many limitations that UILocalNotificationhas. Many apps (included mine) had solve the problem creating a queue of notifications. I explain that topic here
Related
Im building a Calendar app, where you can schedule events, and you get Notified by UserNotification.
The Problem is that i recently read that you can only have 64 scheduled events. But what if the user has more than 64 events? I know repeated notifications are counted as one.
Does this limit count for all notification types (Timer,Calendar,Loacation)?
How would u solve this issue? Since i don't use a server, i cant make push/remote notifications.
Looking forward to ur answers!
Thanks in advance!
After the 64th event, you can try to save the ones after that and schedule them once the number of current scheduled event is less than 64. You should take into account the event's schedule time to avoid missing event with sooner start date.
EDIT
Since your app allows user to schedule future events, it makes sense to use CoreData to persist data. For each event they created, you can create an entity with following attributes:
event name
event start date
isScheduled boolean
This should be fairly simple. After that, whenever the app starts, you can fetch the events and schedule the ones with closest start date. This way, you don't have to schedule an event too far ahead.
If you want to check the number of scheduled events, you can do
UIApplicaiton.shared.scheduledLocalNotifications?.count
This method works but it is deprecated so you might want to use
UNUserNotificationCenter.getPendingNotificationRequests
I am trying to create a repeating local notification that will notify the user every hour between a set time every week day (e.g. 9-5 monday-friday) but after searching cant find any documentation on how to implement this.
If you want only 5/7 it can be a problem.
When you schedule a local notification you can also set a calendar unit as -repeatInterval property. This is cool because there is an per-app limit (maybe 64) of maximum number of notification that you can schedule, thus creating one you can fire it each day at the same time.
If you need to create a different kind of repetition is easy to reach that limit, to avoid that you can recreate further notifications each time the user open the app, or if you implement interactive notifications, each time the user interact with one.
Or but I've never tried you can create a notification for each day of the week NSWeekCalendarUnit(except sat and sun) an set the repetition to weekday for each, in this way you will only spend 5 notifications, for infinite repetition.
I need to have a logic in our app, which allows to define recurring events (e.g. every tuesday, oder every 1st day of a month) which lead then to a specific action in the app.
I thought UILocalNotification would be a good idea, but with this class I send a notification also to the user and I want to process the event only in the app (If the app is not online, then may be the next time the app is up)
Another idea was to set up a list with the event and check every time the app is up, whether an event is due - but this seems quite old fashioned - hope there is something better.
Thanks a lot for any suggestion
You definitely want to use UILocalNotification in your situation, it will completely fulfill the needs that you described.
Since you said, the event should only fire whenever the app is active (in foreground) you will have to add some custom logic to make this happen, but this is not a very difficult task and you have multiple options here.
What I would suggest is that you use the app lifecycle methods of your AppDelegate, to schedule and remove your notifications when it's appropriate.
The UIApplicationDelegate protocol contains two relevant methods for your case (actually a bit more, but these two will do the job for you...). First we have applicationWillEnterBackground:, that's where you should remove all currently scheduled notifications. In the method applicationDidBecomeActive: you can then reschedule the notifications, as this one is called every time your app is coming to the foreground again.
Let me know if you have further questions :)
I just want to but sure I'm understanding this correctly.
It looks like the only way to have an UILocalNotification repeat ONLY ONCE 2 minutes after the first one is to schedule 2 separate local notifications.
Is that right?
I have seen posts similar to these:
How do I create a UILocalNotification that notifies every two minutes
https://stackoverflow.com/a/4923276/454404
https://stackoverflow.com/a/4022779/454404
They all seem to suggest the "schedule 2 notifications" route.
The Apple docs clearly say that you use Calendar units for repeats. So I guess you could set one to repeat a certain number of seconds after but then you would have to cancel it.
It just seems like there must be a better way.
Thanks
Have not found a better way that this.
I'm building an online calendar in Ruby on Rails that needs to send out email notifications whenever a user-created event is about to start/finish (i.e you get a reminder when a meeting is 5 minutes away). What's the best way of figuring out when an event is about to start? Would there be a cron task that checks through all events to find out which ones are starting within a certain threshold (i.e 5 minutes) ? A cron task seems inefficient to me, so I'm wondering what might be a better solution. My events are stored in a mySQL database. There must be a design pattern for this... I'm just at a loss for what to search for.
Any help would be greatly appreciated. Thanks.
In all likelihood you will probably implement some background queuing mechanism to actually deliver the notifications - at least you certain should be considering this approach.
Assuming this, why not create your delayed notification jobs at event creation time to be delivered when the associated event is starting or finishing. The background queue, which is already waking up periodically to look for work, will pick these up and run them.
However adopting this approach requires you to consider the following (at least):
Removing queued notification job if the associated event is removed
Amending the notification job if the associated event is amended (say a new time)
Ensuring that the polling resolution of the queuing system does not allow notifications to be delivered so late as to be useless.
If you haven't picked a queuing solution for your application you should consider these options