diff --git a/Sources/KlaviyoSwift/Klaviyo.swift b/Sources/KlaviyoSwift/Klaviyo.swift index dbd1e9f1..35558d5e 100644 --- a/Sources/KlaviyoSwift/Klaviyo.swift +++ b/Sources/KlaviyoSwift/Klaviyo.swift @@ -142,10 +142,9 @@ public struct KlaviyoSDK { /// Set the current user's push token. This will be associated with profile and can be used to send them push notificaitons. /// - Parameter pushToken: String formatted push token. public func set(pushToken: String) { - environment.getNotificationSettings { enablement in - dispatchOnMainThread(action: .setPushToken( - pushToken, - enablement)) + Task { + let enablement = await environment.getNotificationSettings() + dispatchOnMainThread(action: .setPushToken(pushToken, enablement)) } } diff --git a/Sources/KlaviyoSwift/KlaviyoEnvironment.swift b/Sources/KlaviyoSwift/KlaviyoEnvironment.swift index 85a8e85b..63e2ba64 100644 --- a/Sources/KlaviyoSwift/KlaviyoEnvironment.swift +++ b/Sources/KlaviyoSwift/KlaviyoEnvironment.swift @@ -36,7 +36,7 @@ struct KlaviyoEnvironment { var getUserDefaultString: (String) -> String? var appLifeCycle: AppLifeCycleEvents var notificationCenterPublisher: (NSNotification.Name) -> AnyPublisher - var getNotificationSettings: (@escaping (KlaviyoState.PushEnablement) -> Void) -> Void + var getNotificationSettings: () async -> KlaviyoState.PushEnablement var getBackgroundSetting: () -> KlaviyoState.PushBackground var legacyIdentifier: () -> String var startReachability: () throws -> Void @@ -58,10 +58,9 @@ struct KlaviyoEnvironment { NotificationCenter.default.publisher(for: name) .eraseToAnyPublisher() }, - getNotificationSettings: { callback in - UNUserNotificationCenter.current().getNotificationSettings { settings in - callback(.create(from: settings.authorizationStatus)) - } + getNotificationSettings: { + let notificationSettings = await UNUserNotificationCenter.current().notificationSettings() + return KlaviyoState.PushEnablement.create(from: notificationSettings.authorizationStatus) }, getBackgroundSetting: { .create(from: UIApplication.shared.backgroundRefreshStatus) }, legacyIdentifier: { "iOS:\(UIDevice.current.identifierForVendor!.uuidString)" }, diff --git a/Tests/KlaviyoSwiftTests/KlaviyoTestUtils.swift b/Tests/KlaviyoSwiftTests/KlaviyoTestUtils.swift index 251cecb4..684da321 100644 --- a/Tests/KlaviyoSwiftTests/KlaviyoTestUtils.swift +++ b/Tests/KlaviyoSwiftTests/KlaviyoTestUtils.swift @@ -82,7 +82,7 @@ extension KlaviyoEnvironment { getUserDefaultString: { _ in "value" }, appLifeCycle: AppLifeCycleEvents.test, notificationCenterPublisher: { _ in Empty().eraseToAnyPublisher() }, - getNotificationSettings: { callback in callback(.authorized) }, + getNotificationSettings: { .authorized }, getBackgroundSetting: { .available }, legacyIdentifier: { "iOS:\(UUID(uuidString: "00000000-0000-0000-0000-000000000002")!.uuidString)" }, startReachability: {},