Hello,
I have an issue with LocalNotifications on my App.
On my App the user can schedule a Notification to get a reminder when a contract expires. He can choose the date and time himself.
However I have repeatedly been getting E-Mails from users, saying that their Notifications do not work.
When testing on my own personal device however, I have no issue and they work fine.
I was wondering if I was missing some comprehension about LocalNotifications. Do they expire at some point? Does the UNUserNotificationCenter delete queued notifications when a device is turned off? Are there any possible reasons for this behaviour?
Any help would be greatly appreciated as I couldn't find any info online.
I included my code for creating a LocalNotification below:
I have an issue with LocalNotifications on my App.
On my App the user can schedule a Notification to get a reminder when a contract expires. He can choose the date and time himself.
However I have repeatedly been getting E-Mails from users, saying that their Notifications do not work.
When testing on my own personal device however, I have no issue and they work fine.
I was wondering if I was missing some comprehension about LocalNotifications. Do they expire at some point? Does the UNUserNotificationCenter delete queued notifications when a device is turned off? Are there any possible reasons for this behaviour?
Any help would be greatly appreciated as I couldn't find any info online.
I included my code for creating a LocalNotification below:
Code Block /** Schedules a local notification. - parameter company: String! of the contracts company name. - parameter name: String! of the contracts name. - parameter datum: Date! of the reminder. - returns: String of NotificationID. */ static func scheduleNotification(company: String!, name: String!, datum: Date!) -> String! { let notificationID = arc4random() let content = UNMutableNotificationContent() content.title = NSLocalizedString("Kündigungserinnerung ", comment: "") + company content.body = NSLocalizedString("Falls Sie Ihren ", comment: "") + name + NSLocalizedString(" Vertrag kündigen möchten, wäre jetzt der richtige Zeitpunkt dafür! 📄", comment: "") content.categoryIdentifier = Notification.Category.Local.identifier content.userInfo = ["NotificationID": notificationID] content.sound = UNNotificationSound.default() let calendar = Calendar.current let components = calendar.dateComponents([.year, .month, .day, .hour, .minute], from: datum) let finalComponents = NSDateComponents() finalComponents.year = components.year! finalComponents.month = components.month! finalComponents.day = components.day! finalComponents.hour = components.hour! finalComponents.minute = components.minute! let trigger = UNCalendarNotificationTrigger(dateMatching: finalComponents as DateComponents, repeats: false) let requestIdentifier = "request" let request = UNNotificationRequest(identifier: requestIdentifier, content: content, trigger: trigger) UNUserNotificationCenter.current().add(request, withCompletionHandler: { error in if error != nil { log.error(error!) } }) return String(notificationID) }