Repeating Local Notifications at specific intervals - ios

Is it possible to have a notification repeat at specific intervals? For example, Remind me to do something on Monday to Friday (from 9:00am to 6:00pm)?

You can schedule local notifications for the specific time, date, weekday, and also specify to be repeated or not.
Here is a comprehensive document provided by Apple that describes how to do it.
If I'm not mistaken, You mean to schedule notification for a continuous period of time, If so, It does not make sense and it's not possible.
But you can schedule multiple notifications for different times of a weekday based on your need.

Related

How to check for time every minutes in Rails

Let's say I want to build a Reminder App. It allow user to set a time which will remind them to do their work. For example: 24th March 07:03 PM.
The easiest way I can think of is to use whenever gem and set a crontab every minutes and check if there is any reminder needs to be fire.
But I was wondering if there is a better way to achieve this. Or if now users want to set a reminder in seconds, what can I do? For example: 24th March 07:03:33 PM.
Another way to do this and be accurate to seconds is with a delayed background job.
For example resque_scheduler
When a user creates a reminder you enqueue a job at specific time.
reminder = Reminder.last
# assuming reminder has a column reminder_at and there is
# a job that processes these reminders, ProcessReminderJob
Resque.enqueue_at(reminder.remind_at, ProcessReminderJob, reminder.id)

Local Notifications limit for Calendar app

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

Swift: Creating a repeating local notification between a set time each day

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.

UILocalNotification repeat alert 2 minutes later

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.

Can I change the message in a repeating UILocalNotification?

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

Resources