diff --git a/Knock.podspec b/Knock.podspec index 5aed77b..870d228 100644 --- a/Knock.podspec +++ b/Knock.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |spec| spec.name = "Knock" - spec.version = "1.1.0" + spec.version = "1.1.1" spec.summary = "An SDK to build in-app notifications experiences in Swift with Knock.." spec.description = <<-DESC diff --git a/Sources/Knock.swift b/Sources/Knock.swift index 93754a0..a0e1607 100644 --- a/Sources/Knock.swift +++ b/Sources/Knock.swift @@ -10,7 +10,7 @@ import OSLog // Knock client SDK. public class Knock { - internal static let clientVersion = "1.1.0" + internal static let clientVersion = "1.1.1" public static var shared: Knock = Knock() diff --git a/Sources/KnockAppDelegate.swift b/Sources/KnockAppDelegate.swift index ed31bae..ae517d8 100644 --- a/Sources/KnockAppDelegate.swift +++ b/Sources/KnockAppDelegate.swift @@ -54,10 +54,10 @@ open class KnockAppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificat open func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { Task { - let channelId = await Knock.shared.environment.getPushChannelId() + let channelId = await Knock.shared.getPushChannelId() do { - let _ = try await Knock.shared.channelModule.registerTokenForAPNS(channelId: channelId, token: Knock.convertTokenToString(token: deviceToken)) + let _ = try await Knock.shared.registerTokenForAPNS(channelId: channelId, token: Knock.convertTokenToString(token: deviceToken)) } catch let error { Knock.shared.log(type: .error, category: .pushNotification, message: "didRegisterForRemoteNotificationsWithDeviceToken", description: "Unable to register for push notification at this time", status: .fail, errorMessage: error.localizedDescription) } diff --git a/Sources/KnockEnvironment.swift b/Sources/KnockEnvironment.swift index fac7733..49e1d4c 100644 --- a/Sources/KnockEnvironment.swift +++ b/Sources/KnockEnvironment.swift @@ -127,3 +127,48 @@ internal actor KnockEnvironment { defaults.array(forKey: previousPushTokensKey) as? [String] ?? [] } } + +public extension Knock { + + func setUserInfo(userId: String?, userToken: String?) async { + await environment.setUserInfo(userId: userId, userToken: userToken) + } + + func setUserInfo(userId: String?, userToken: String?, completion: @escaping () -> Void) { + Task { + await environment.setUserInfo(userId: userId, userToken: userToken) + completion() + } + } + + /// Returns the userId that was set from the Knock.shared.signIn method. + func getUserId() async -> String? { + await environment.getUserId() + } + + func getUserId(completion: @escaping (String?) -> Void) { + Task { + completion(await environment.getUserId()) + } + } + + func getDeviceToken() async -> String? { + await environment.getDeviceToken() + } + + func getDeviceToken(completion: @escaping (String?) -> Void) { + Task { + completion(await environment.getDeviceToken()) + } + } + + func getPushChannelId() async -> String? { + await environment.getPushChannelId() + } + + func getPushChannelId(completion: @escaping (String?) -> Void) { + Task { + completion(await environment.getPushChannelId()) + } + } +} diff --git a/Sources/Modules/ChannelModule.swift b/Sources/Modules/ChannelModule.swift index bffc824..810864c 100644 --- a/Sources/Modules/ChannelModule.swift +++ b/Sources/Modules/ChannelModule.swift @@ -246,11 +246,11 @@ public extension Knock { - channelId: the id of the APNS channel - token: the APNS device token as a `String` */ - func registerTokenForAPNS(channelId: String, token: String) async throws -> ChannelData { + func registerTokenForAPNS(channelId: String?, token: String) async throws -> ChannelData { return try await self.channelModule.registerTokenForAPNS(channelId: channelId, token: token) } - func registerTokenForAPNS(channelId: String, token: String, completionHandler: @escaping ((Result) -> Void)) { + func registerTokenForAPNS(channelId: String?, token: String, completionHandler: @escaping ((Result) -> Void)) { Task { do { let channelData = try await registerTokenForAPNS(channelId: channelId, token: token) diff --git a/Sources/Modules/UserModule.swift b/Sources/Modules/UserModule.swift index a08a634..6d42fe3 100644 --- a/Sources/Modules/UserModule.swift +++ b/Sources/Modules/UserModule.swift @@ -36,17 +36,6 @@ internal class UserModule { public extension Knock { - /// Returns the userId that was set from the Knock.shared.signIn method. - func getUserId() async -> String? { - await environment.getUserId() - } - - func getUserId(completion: @escaping (String?) -> Void) { - Task { - completion(await environment.getUserId()) - } - } - /** Retrieve the current user, including all properties previously set. https://docs.knock.app/reference#get-user