My calendar app is not connected to Event Kit which allows me to create custom repeating intervals like "every 3 days, 29 times" etc.
Now i would like to add Notifications to my Events ... but my custom repeating events are limiting me in every possible way.
I think I have checked every possible solution:
UILocalNotification
UILocalNotification is limited to 64 events and NSCalendarUnit's in-built Unit Time Intervals aren't very flexible.
1 event repeated every 2 days will fill this up very quickly
Should i reschedule 64 Notifications on every app start and beg the user to start the app regularly? Not running the app for a while will not reschedule notifications.
Event Kit (Calendars & Reminders)
I could create a calendar or Reminder list, generate single events from the custom repeating events and add notifications here. But the user can edit this, which will cause confusion.
I can't synch this back to my app.
Should i create a calendar or reminder list for Alerts and hope that the user will not touch this?
Apple Push Notification Service
Everywhere i can read: They are not reliable! There is no guarantee that push notifications will actually be delivered, even if the APNS server accepted them.
I think push notifications are not made for notifying the user at scheduled times as there is no guarantee they will arrive.
The question is what should i do, or what would you do in my case? No solution is perfect and i am hoping to find the most user friendly approach here. In case i am missing a approach, i would like to hear the alternative.
Edit:
Adding a another method for completeness.
UILocalNotification without repeats
don't offer the repeating of local notifications. The user can assign single Notifications to a event. After enabling the 65th notification, a popup will remind him that he has reached the system limit. This way you put the responsibility to the user. After reaching the limit he will be forced to focus on events that are not far in the future.
You could save all your events to core data and then every time the app is launched or when your main view appears load in all events for that week and set a scheduled local notification. Once the event is scheduled you set a flag in the entity eg hasBeenNotified.
Hope it helps.
I decided to offer local notifications without repeat functionality.
This decision was made after chatting with a few users.
Better to offer something than to offer nothing :)
Related
I have an app that allows users to create recurrent events. Each one of the events may or may not have reminder/alerts at a specific time of day. If they have so, the app sends a local notification at that time of day.
Events are stored in CoreData.
Event(name: "Go to London",
date: 2020-04-03 21:40:55.419925+0200,
reminders: [2020-04-03 20:00:00.419925+0200,
2020-04-03 10:00:00.419925+0200,
2020-04-03 12:00:00.419925+0200]
)
An event may occur on each day of the year or everyday for the next X years.
A user may create unlimited number of events per day. And hence, the total number of notifications to be sent can easily surpasses 64 (total number of local notification that you can schedule in iOS). So I can not schedule all the notifications while the app is in foreground.
I need a mechanism to periodically schedule notifications if there are less than 64 notifications pending. This should be done even if the app is in the background.
I would be happy if you provide a solution or guide me towards finding a solution for this scenario.
info
I tried to set up a Timer that periodically checks total number of pending notifications and their due dates. . But it did not work, because timers won’t fire once the app goes in background.
I am not sure if I understand your problem right. But my impression is the following:
Your users set up and update a database of events where each event has a certain date and time.
They do this simply be entering new events into the database.
It is easy then to fetch the first n (say, 10) events from the database.
It is required to fetch more than one, since the delivery of a local notification is not guaranteed, see the docs:
Every attempt is made to deliver local and remote notifications in a
timely manner, but delivery isn't guaranteed.
Register these n local notifications with the notification center, and cancel any notification for events that are no longer among the n next ones. The docs say:
Typically, you cancel a request when conditions change and you no
longer need to notify the user. For example, if the user completes a
reminder, you would cancel any active requests associated with that
reminder. To cancel an active notification request, call the
removePendingNotificationRequests(withIdentifiers:) or
removePendingNotificationRequests(withIdentifiers:) method of
UNUserNotificationCenter.
So, even if your app is in the background or suspended, the local notification will wake it up, handle the event, remove it from the database, and update the n next events. Even if a notification could not be delivered (which is not probably, but possible), you could handle the missed event, and schedule the next ones.
I hope this meets your requirements!
Have you tried the background fetch feature? Official document link here.
And in my opinion, it would be better to use remote notification, just setup a simple server to store the users' data.
As I see in many apps when setting user notifications as reminders, it works fine but after a while when the user starts to ignore opening the notification or the app it won't send any more notifications.
Is there a way to disable this behavior and continue sending the notifications even if they don't open the app?
What you are describing sounds like local notifications. These are scheduled in code to go off at a specific time. As far as I know there is no such thing as a recurring local notification. They are "simulated" by creating many single local notifications to begin with.
Edit
As PaulW pointed out. Recurring notifications are possible but are rarely used due to their limitations.
When the app is opened it runs some code to create some more local notifications.
If the app is not opened then the code never runs to create the additional notifications.
So, in this example, it is not iOS stopping the recurring notifications because you haven't opened the app. The notifications stop recurring because you don't open the app and give it the opportunity to create more of them.
So, to answer your question. No. The only way to delay this as long as possible is to create notifications that cover a long time into the future. But then I believe there is a limit to the number of scheduled notifications. (A quick google comes up with a limit of 64 scheduled notifications per app).
Edit you could also use repeating notifications but they are limited to repeat every one unit of time. Once a day, once and hour, once a minute, etc... so you can't do it every two hours.
Alternatively you could use a backend to send remote notifications. These could theoretically recur infinitely because the app is not required to create them. Of course, this assumes you have the infrastructure setup to develop this.
I have 8 medicine local notifications which differ from day to day.
They work fine for one day but I want to fire them everyday. I used BackgroundFetch to reschedule the local notifications every time fetch is executed. But my problem here is that background fetch depends on how often the user uses the app. What if the user doesn't open the app more often Also I didn't want to implement silent notifications because it will not wake up the app if the user does not have internet connection. what approach should I use instead of background fetch?
EDIT:
I also thought about location updates in background because my notification times are taken from location of user and calculated accordingly. But will this consume a lot of battery?
Since I've got the same issue in an
app that probably does the same stuff as yours, I'd like to share my solution.
It comes with one compromise works only from >=iOS8.
By using an interactive notifications you can reschedule your notifications in background, of course the user need to interact with the notification, but I think that if you different actions instead of open the app or cancel the notification is possible to have more interested user.
It's all about creating a configuration with actions.
Here you can find a tutorial.
I would like to know what is the best approach to do if I want to fire notifications for more than one time each day everyday.
I did some research and read that notifications for the next day cannot be fired unless the user opens the app the next day and updated the notification. Is that true? is there anyway I can do it without the need of the user opening the app everyday?
Thank you
You can schedule up to 64 local notifications. There is no limit on the time period; you can schedule them years in advance if you like.
That said, if you need some mechanism to schedule new notifications, even if the app is not running at all (e.g. because the user terminated it), you need a background mode for that. Fetch is probably the way to go here, as it doesn't need a special trigger. You could also send silent push notifications in order to wake the app, make the calculations and schedule the new notifications.
Overview
I have an iOS app which sends local notifications at specific dates.
I just learned that I can only schedule 64 notifications at a given time.
There are cases when I can't schedule notifications as the 64 slots are filled.
So I store them in the database and when the user responds to a notification I check if there are any available slots and schedule the remaining notifications.
Problem
When the user doesn't respond to a notification my code is not executed so I am not able to schedule the remaining notifications.
Question
Is there a solution for this problem ?
can I execute a piece of code (house keeping) at certain times ?
is there any work around for this ?
You may not want to signal to the user there is a problem, but rather just do it in the background. If a user has 64 notifications for one app and hasn't opened the app, then they probably aren't using the app. Once a notification has fired it isn't in the array anymore. So you will have room every time a notification is fired off. They do however remain in notification centre, which you have to clear out yourself.
Its usually better to not present possible problems to the user, but rather handle them in a way that makes sense internally if that is an option. Look up the delegate methods for the appDelegate and you will most likely find ways you can handle what you are trying to do.
Thought I would make a post in case you wanted to accept the answer.
Best of luck.