User notification are restricted to a limit in iOS app how to send unlimited for alarm app?

1.4k Views Asked by At

I am working on an alarm app project(Click for GitHub link) this code is working fine but the problem is notifications are limited to approximately 64 at the time so I am unable to send continues notification until the user responds to the notification. I read some the apple restricts local notification to only 64 but I have seen many apps on apple store those are sending notification continuously here few links from the apple store.

https://itunes.apple.com/us/app/red-clock-free-edition-the-minimal-alarm-clock/id567374573?mt=8 https://itunes.apple.com/us/app/alarmy-alarm-clock/id1163786766?mt=8

Anyone help to understand how this app is able to send continuously and I tried these apps are sending notification until the user responds to the app (for more than 1 hr I checked). Below is the code for setting single notification.

    let comingSunday =  findNext("Sunday", afterDate: fireDate.adding(minutes: item))
    let triggerDate = Calendar.current.dateComponents([ .year, .month, .weekday, .hour, .minute, .second], from: comingSunday!)
    let trigger = UNCalendarNotificationTrigger(dateMatching: triggerDate, repeats: alarm.repeatAlarm)

    let request = UNNotificationRequest(identifier: "\(alarm.uuid)0\(item)", content: notificationContent, trigger: trigger)
    UNUserNotificationCenter.current().add(request) { (error) in
                         if let error = error {
                           print("Unable to add notification request, \(error.localizedDescription)")
                         }
    }

Video of Alarmy app with continuous notification

Please install and run app from App Store and notice how notification are working in above apps before posting answer

3

There are 3 best solutions below

0
On
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Swift.Void)

The Delegate only works when the app is running

0
On

You could store information about all your notifications in the local database.

For example, if you have more than 64 notifications, you can post 64 notifications via UNUserNotificationCenter, and others save to the local database.

If one of local notification completed (already presented), you could get information about the first notification from the local database and schedule it (also you can remove it from the local database, or add specify key (isScheduled for example)).

You can handle this operation in the delegate method:

func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Swift.Void)
1
On

may be trivial, but if You simply need to be notificated more times, I usually use:

UNTimeIntervalNotificationTrigger( timeInterval: 60.0, repeats: true)

SO you can add ONE that counts for one, and it can coexists with your other (real) notification. Once user has tapped, You can kill it.