Is the iOS Local Notification Limit Per Day? - ios

I'm working on an app where I need to send a good amount of notifications to the user daily. Around 5-40 depending on the user.
I'm using local notifications to send it, but I know there is a 64 notification limit. Does this mean 64 notifications per day, or in total?

It means simultaneously scheduled for future delivery. You can send as many as you want per day, provided they don't overlap.
If you add more than 64 requests (under UserNotifications) or scheduled (under UIApplication/UILocalNotification), the older ones will be dropped and not delivered.

Unfortunately iOS limits the local schedule notification up to 64. May be to prevent this issue can schedule first group of notification initially and then schedule another group when launch the app next time.

Related

ios - Schedule unlimited number of local notifications

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.

iOS local notifications disabled automatically if app isn't opened

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.

Is ios blocking local notifications considered as harmful?

I have an app made with phonegap which is using a third-party plugin for displaying local notifications. (https://github.com/katzer/cordova-plugin-local-notifications)
I deployed it on my device, and in the beginning it worked well. However after the app sent dozens of notifications (very frequently and with same text) at some point my iphone started not showing the notifications. I tried to delete the app, and deploy again, then the confirmation dialog popped up again for allowing notifications from the app, but they still didn't show up.
When i deployed it on an other device, it worked well again, also in the emulator.
Is it possible that ios somehow blocked notifications from this app, because it considered them as harmful/spam?
Maximum number of scheduled notification is 64. If you are reached the maximum you can't add more local notifications without removing the old ones or after firing the scheduled notifications.
In the apple documents, it mentions as follows
Each app on a device is limited to 64 scheduled local notifications.
The system discards scheduled notifications in excess of this limit,
keeping only the 64 notifications that will fire the soonest.
Recurring notifications are treated as a single notification.
There is a limit of 64 scheduled notifications per app, so, if you schedule more - only first 64 will arive.
Each app on a device is limited to 64 scheduled local notifications. The system discards scheduled notifications in excess of this limit, keeping only the 64 notifications that will fire the soonest. Recurring notifications are treated as a single notification.
However, there is a way to be sure that all 64 are scheduled - just pass them in packs by 64 notifications each.
Check this answer for more info.

Show local notifications without limit

I have a swift 2 app in which you can create entries in Core Data.
Each entry will register a local notification.
The problem is the limit of 64 local notifications.
Is there an way to solve this "problem" with the limitation?
Kind of (thanks #dfri). However, repeated notifications only count as one notification, but it appears that you have 64 completely independent notifications.
From the Local and Remote Notification Programming Guide:
Each app on a device is limited to 64 scheduled local notifications. The system discards scheduled notifications in excess of this limit, keeping only the 64 notifications that will fire the soonest. Recurring notifications are treated as a single notification.
The only semi-viable alternative is (see this repo):
Hope that your users open your app within 64 notifications.
Schedule remaining notifications.

UILocalNotification Maximum Discrepancy

In Apple's Local and Push Notification Programming Guide, it says:
Each application on a device is
limited to the soonest-firing 64
scheduled local notifications. The
operating system discards
notifications that exceed this limit.
It considers a recurring notification
to be a single notification. LINK
However, in the iOS Application Programming Guide, it says
Listing 4-3 shows an example that
schedules a single alarm using a date
and time that is set by the user. This
example configures only one alarm at a
time and cancels the previous alarm
before scheduling a new one. (Your own
applications can have no more than 128
local notifications active at any
given time, any of which can be
configured to repeat at a specified
interval.) LINK
Which of these is true? Do I get 64 notifications or 128 notifications?
I finally did a test, and the answer is 64 local notifications.

Resources