From ffa278884a4c61262a0cdc227084e838a8649c89 Mon Sep 17 00:00:00 2001 From: Anian Schleyer <98647423+anian03@users.noreply.github.com> Date: Tue, 19 Nov 2024 11:29:36 +0100 Subject: [PATCH] `Notifications`: Add support for app extension notifications (#103) * Add notification function for app extension * Update notification register request --- .../PushNotifications/PushNotificationHandler.swift | 11 +++++++++++ .../PushNotificationServiceImpl.swift | 1 + 2 files changed, 12 insertions(+) diff --git a/Sources/PushNotifications/PushNotificationHandler.swift b/Sources/PushNotifications/PushNotificationHandler.swift index b4f630b..ceb0401 100644 --- a/Sources/PushNotifications/PushNotificationHandler.swift +++ b/Sources/PushNotifications/PushNotificationHandler.swift @@ -12,6 +12,17 @@ import UserNotifications public class PushNotificationHandler { + public static func extractNotification(from payload: String, iv: String) async -> UNMutableNotificationContent? { + log.verbose("Notification received with payload: \(payload)") + + guard let notification = PushNotificationCipher.decrypt(payload: payload, iv: iv) else { + log.verbose("Notification could not be decrypted.") + return nil + } + + return await prepareNotification(notification) + } + public static func handle(payload: String, iv: String) { log.verbose("Notification received with payload: \(payload)") diff --git a/Sources/PushNotifications/Services/PushNotificationService/PushNotificationServiceImpl.swift b/Sources/PushNotifications/Services/PushNotificationService/PushNotificationServiceImpl.swift index fcfdad3..cec8fc4 100644 --- a/Sources/PushNotifications/Services/PushNotificationService/PushNotificationServiceImpl.swift +++ b/Sources/PushNotifications/Services/PushNotificationService/PushNotificationServiceImpl.swift @@ -60,6 +60,7 @@ class PushNotificationServiceImpl: PushNotificationService { var token: String var deviceType = "APNS" + var apiType = 1 var method: HTTPMethod { return .post