From 1e5300bbf5e1d6f9e7afc72cb39b185b57cdc593 Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 8 Aug 2025 20:19:31 -0500 Subject: [PATCH 1/2] Converts NotificationSchedule enum to a dictionary to fix crash while scheduleing notifications. --- .../ios/Sources/Notification.swift | 65 +++++++++++++++++-- 1 file changed, 61 insertions(+), 4 deletions(-) diff --git a/plugins/notification/ios/Sources/Notification.swift b/plugins/notification/ios/Sources/Notification.swift index adba05ec25..259399b8d4 100644 --- a/plugins/notification/ios/Sources/Notification.swift +++ b/plugins/notification/ios/Sources/Notification.swift @@ -38,10 +38,17 @@ func makeNotificationContent(_ notification: Notification) throws -> UNNotificat arguments: nil) } - content.userInfo = [ - "__EXTRA__": notification.extra as Any, - "__SCHEDULE__": notification.schedule as Any, - ] + var userInfo: [String: Any] = [:] + + if let extra = notification.extra { + userInfo["__EXTRA__"] = extra + } + + if let schedule = notification.schedule { + userInfo["__SCHEDULE__"] = scheduleToDictionary(schedule) + } + + content.userInfo = userInfo if let actionTypeId = notification.actionTypeId { content.categoryIdentifier = actionTypeId @@ -66,6 +73,56 @@ func makeNotificationContent(_ notification: Notification) throws -> UNNotificat return content } +func scheduleToDictionary(_ schedule: NotificationSchedule) -> [String: Any] { + switch schedule { + case .at(let date, let repeating): + return [ + "type": "at", + "date": date, + "repeating": repeating + ] + case .interval(let interval): + return [ + "type": "interval", + "interval": scheduleIntervalToDictionary(interval) + ] + case .every(let interval, let count): + return [ + "type": "every", + "interval": interval.rawValue, + "count": count + ] + } +} + +func scheduleIntervalToDictionary(_ interval: ScheduleInterval) -> [String: Any] { + var dict: [String: Any] = [:] + + if let year = interval.year { + dict["year"] = year + } + if let month = interval.month { + dict["month"] = month + } + if let day = interval.day { + dict["day"] = day + } + if let weekday = interval.weekday { + dict["weekday"] = weekday + } + if let hour = interval.hour { + dict["hour"] = hour + } + if let minute = interval.minute { + dict["minute"] = minute + } + if let second = interval.second { + dict["second"] = second + } + + return dict +} + func makeAttachments(_ attachments: [NotificationAttachment]) throws -> [UNNotificationAttachment] { var createdAttachments = [UNNotificationAttachment]() From 0f623cf21e16faf43a4b2194829436647212879d Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Thu, 21 Aug 2025 08:35:43 -0300 Subject: [PATCH 2/2] change file --- .changes/fix-notification-schedule-ios.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changes/fix-notification-schedule-ios.md diff --git a/.changes/fix-notification-schedule-ios.md b/.changes/fix-notification-schedule-ios.md new file mode 100644 index 0000000000..481cba1b6f --- /dev/null +++ b/.changes/fix-notification-schedule-ios.md @@ -0,0 +1,6 @@ +--- +"notification": patch +"notification-js": patch +--- + +Fix notification scheduling on iOS.