From 3c864a5e448f25498d9c5aa215b8c685a5ca92b5 Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Mon, 1 May 2023 12:57:10 -0300 Subject: [PATCH] save notification --- .../notification/ios/Sources/NotificationHandler.swift | 8 ++++++-- plugins/notification/ios/Sources/NotificationPlugin.swift | 8 ++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/plugins/notification/ios/Sources/NotificationHandler.swift b/plugins/notification/ios/Sources/NotificationHandler.swift index 40fe5608..5f74a855 100644 --- a/plugins/notification/ios/Sources/NotificationHandler.swift +++ b/plugins/notification/ios/Sources/NotificationHandler.swift @@ -5,7 +5,11 @@ public class NotificationHandler: NSObject, NotificationHandlerProtocol { public weak var plugin: Plugin? - var notificationsMap = [String: JSObject]() + private var notificationsMap = [String: JSObject]() + + public func saveNotification(_ key: String, _ notification: JSObject) { + notificationsMap.updateValue(notification, forKey: key) + } public func requestPermissions(with completion: ((Bool, Error?) -> Void)? = nil) { let center = UNUserNotificationCenter.current() @@ -72,7 +76,7 @@ public class NotificationHandler: NSObject, NotificationHandlerProtocol { var notification = makePendingNotificationRequestJSObject(request) notification["sound"] = notificationRequest["sound"] ?? "" notification["actionTypeId"] = request.content.categoryIdentifier - notification["attachments"] = notificationRequest["attachments"] ?? [] + notification["attachments"] = notificationRequest["attachments"] ?? [JSObject]() return notification } diff --git a/plugins/notification/ios/Sources/NotificationPlugin.swift b/plugins/notification/ios/Sources/NotificationPlugin.swift index f35a3cd0..290197a0 100644 --- a/plugins/notification/ios/Sources/NotificationPlugin.swift +++ b/plugins/notification/ios/Sources/NotificationPlugin.swift @@ -61,18 +61,18 @@ func showNotification(invoke: Invoke, notification: JSObject) } class NotificationPlugin: Plugin { - let notificationHandler = NotificationHandler() + var notificationHandler = NotificationHandler() let notificationManager = NotificationManager() override init() { super.init() - notificationHandler.plugin = self notificationManager.notificationHandler = notificationHandler + notificationHandler.plugin = self } @objc public func show(_ invoke: Invoke) throws { let request = try showNotification(invoke: invoke, notification: invoke.data) - // TODO self.notificationHandler.notificationsMap[request.identifier] = invoke.data + notificationHandler.saveNotification(request.identifier, invoke.data) invoke.resolve([ "id": Int(request.identifier) ?? -1 ]) @@ -87,7 +87,7 @@ class NotificationPlugin: Plugin { for notification in notifications { let request = try showNotification(invoke: invoke, notification: notification) - // TODO self.notificationHandler.notificationsMap[request.identifier] = notification + notificationHandler.saveNotification(request.identifier, notification) ids.append(Int(request.identifier) ?? -1) }