From 3d301c654e6f5e7f343e0e0cbb57648002e98f04 Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Thu, 5 Sep 2024 17:46:04 -0300 Subject: [PATCH] fix(notification): body should be optional on iOS (#1737) --- .changes/notification-body-optional-ios.md | 5 +++++ plugins/notification/ios/Sources/Notification.swift | 8 +++++--- plugins/notification/ios/Sources/NotificationPlugin.swift | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 .changes/notification-body-optional-ios.md diff --git a/.changes/notification-body-optional-ios.md b/.changes/notification-body-optional-ios.md new file mode 100644 index 00000000..3bcdbc75 --- /dev/null +++ b/.changes/notification-body-optional-ios.md @@ -0,0 +1,5 @@ +--- +"notification": patch +--- + +The notification body is now optional on iOS to match the other platforms. diff --git a/plugins/notification/ios/Sources/Notification.swift b/plugins/notification/ios/Sources/Notification.swift index 0f572aa9..adba05ec 100644 --- a/plugins/notification/ios/Sources/Notification.swift +++ b/plugins/notification/ios/Sources/Notification.swift @@ -32,9 +32,11 @@ func makeNotificationContent(_ notification: Notification) throws -> UNNotificat let content = UNMutableNotificationContent() content.title = NSString.localizedUserNotificationString( forKey: notification.title, arguments: nil) - content.body = NSString.localizedUserNotificationString( - forKey: notification.body, - arguments: nil) + if let body = notification.body { + content.body = NSString.localizedUserNotificationString( + forKey: body, + arguments: nil) + } content.userInfo = [ "__EXTRA__": notification.extra as Any, diff --git a/plugins/notification/ios/Sources/NotificationPlugin.swift b/plugins/notification/ios/Sources/NotificationPlugin.swift index c8974b36..9371e83d 100644 --- a/plugins/notification/ios/Sources/NotificationPlugin.swift +++ b/plugins/notification/ios/Sources/NotificationPlugin.swift @@ -65,7 +65,7 @@ struct NotificationAttachment: Codable { struct Notification: Decodable { let id: Int var title: String - var body: String + var body: String? var extra: [String: String]? let schedule: NotificationSchedule? let attachments: [NotificationAttachment]?