Local Notifications stop showing up "after a while"

Hello everybody,

This issue is kinda hard to describe, but I am working on it for quite a while now and probably I am missing the obvious.

I programmed an application, which, among other tasks, reminds the user three times a day to do a task.
The three times are randomly generated (with some distribution rules) and scheduled as local notifications at fixed dates, not repeating for the next two weeks, hence 42 in total.
Notifications get schedules after the app started, stopped, the user changed some data, the server synchronization loaded new data and after background fetches.

A problem reported by a TestFlight tester was, that he did not receive any new notifications, after not opening the application for several days in a row. I checked his system and application Settings for notifications and application background synchronization, which both seemed to be properly configured. Still the notifications stopped showing up, while theoretically they should’n for at least two weeks after the last application activity.

For me the notifications are appearing as intended (three times a day, every day, for several weeks now).
Also I tested the background fetch manually via Xcode (Launch due to a background fetch).

Hence I am aware that this problem is not very detailed regarding the code, I am asking more for a general advise:

1. Am I missing something obvious here or do I make a general mistake (I am not 100% sure, if scheduling local notifications is “allowed” in a background fetch)?
2. Does anyone else here have encountered similar issues and have found the cause or even a solution?
3. Is there a way to reproduce or observe this situation, without “waiting days for the notifications to not appear anymore”?

My best guess, besides that I programmed something wrong, is, that he updated the application or iOS and did not open the application afterwards - I heard that can cause this.

This is my first post here and I am thankful for any constructive advice,
swifter

Hi @swifter,
welcome to RW forums,

How are you setting your local notifications?

cheers,

Hello @jayantvarma,

This is a snipped of the code I use to set the notifications:

private static func schedule(localNotification: LocalNotification, withBadge badge: NSNumber? = nil) {
        // Create the notification content.
        let content = UNMutableNotificationContent()
        content.title = localNotification.title
        content.subtitle = localNotification.subtitle
        content.body = localNotification.body
        content.categoryIdentifier = localNotification.categoryIdentifier
        content.userInfo = localNotification.userInfo
        content.sound = UNNotificationSound.default
        content.badge = badge

        // Create the notification trigger.
        let trigger = UNCalendarNotificationTrigger(
            dateMatching: Calendar.current.dateComponents(
                [.year, .month, .day, .hour, .minute, .second],
                from: localNotification.date
            ),
            repeats: localNotification.repeats
        )

        // Create the request.
        let request = UNNotificationRequest(
            identifier: localNotification.identifier,
            content: content,
            trigger: trigger
        )

        // Add the request.
        UNUserNotificationCenter.current().add(request) {
            (error: Error?) in
        }
    } 

LocalNotification holds all information needed for one notification.

It would be great if there was an easy way to automatically “long-term test” my application like automated UI tests, but just for notifications and in a simulated time span of multiple days… but I hadn’t the time to figure this out yet.

Anyways, thank you for your reply :slight_smile:

This topic was automatically closed after 166 days. New replies are no longer allowed.