Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Knock.podspec
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion Sources/Knock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
4 changes: 2 additions & 2 deletions Sources/KnockAppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
45 changes: 45 additions & 0 deletions Sources/KnockEnvironment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
}
4 changes: 2 additions & 2 deletions Sources/Modules/ChannelModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<ChannelData, Error>) -> Void)) {
func registerTokenForAPNS(channelId: String?, token: String, completionHandler: @escaping ((Result<ChannelData, Error>) -> Void)) {
Task {
do {
let channelData = try await registerTokenForAPNS(channelId: channelId, token: token)
Expand Down
11 changes: 0 additions & 11 deletions Sources/Modules/UserModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down