Search code examples
iphoneiosuilocalnotificationalarmlocalnotification

Do something when local notification arrives or exceed the number of total notifications that can be used


So, I have an exercise app where we have 10/15 Second repetitive timers through which we show the progress done by the User. For making it work on background as well, I have used local notifications. However, as stated by Apple, we can only have ONLY 64 local notifications at any given instance of our app.

So, what happens now is when app is in background and these 64 notifications have finished, I have no control over the app. I can re-add the 64 notifications if the User opens the app. But if User doesn't open the app at all and these 64 notifications are finished then what should I do?

Is there any event which occurs inside the app when any local notification arrives? Is there any way to exceed the number of notifications?

I think there should be a solution as there are many Alarm Apps which work on the same methodology.

Please help!


Solution

  • You can use the repeatInterval property of UILocalNotification to make your notification automatically repeat every second, minute, hour, day, or other unit (see NSCalendarUnit documentation):

    notification.repeatInterval = NSMinuteCalendarUnit;
    

    For your case, this means that you can create 5 notifications with fireDates 10 seconds apart, each with a repeatInterval of NSMinuteCalendarUnit. This will result in the user receiving a notification every 10 seconds indefinitely, and you will have only scheduled 5 notifications, which is well below the limit of 64.

    The only downside of this technique is that there will be no way to stop the notifications until the user opens the app, as you will need to cancel all the notifications to stop them, and you can only do that while the app is running.