Skip to content

Commit 1f4333a

Browse files
authored
Making certain methods in KnockEnvironment public (#9)
1 parent 8d33c0f commit 1f4333a

File tree

6 files changed

+51
-17
lines changed

6 files changed

+51
-17
lines changed

Knock.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |spec|
22
spec.name = "Knock"
3-
spec.version = "1.1.0"
3+
spec.version = "1.1.1"
44
spec.summary = "An SDK to build in-app notifications experiences in Swift with Knock.."
55

66
spec.description = <<-DESC

Sources/Knock.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import OSLog
1010

1111
// Knock client SDK.
1212
public class Knock {
13-
internal static let clientVersion = "1.1.0"
13+
internal static let clientVersion = "1.1.1"
1414

1515
public static var shared: Knock = Knock()
1616

Sources/KnockAppDelegate.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ open class KnockAppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificat
5454

5555
open func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
5656
Task {
57-
let channelId = await Knock.shared.environment.getPushChannelId()
57+
let channelId = await Knock.shared.getPushChannelId()
5858

5959
do {
60-
let _ = try await Knock.shared.channelModule.registerTokenForAPNS(channelId: channelId, token: Knock.convertTokenToString(token: deviceToken))
60+
let _ = try await Knock.shared.registerTokenForAPNS(channelId: channelId, token: Knock.convertTokenToString(token: deviceToken))
6161
} catch let error {
6262
Knock.shared.log(type: .error, category: .pushNotification, message: "didRegisterForRemoteNotificationsWithDeviceToken", description: "Unable to register for push notification at this time", status: .fail, errorMessage: error.localizedDescription)
6363
}

Sources/KnockEnvironment.swift

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,48 @@ internal actor KnockEnvironment {
127127
defaults.array(forKey: previousPushTokensKey) as? [String] ?? []
128128
}
129129
}
130+
131+
public extension Knock {
132+
133+
func setUserInfo(userId: String?, userToken: String?) async {
134+
await environment.setUserInfo(userId: userId, userToken: userToken)
135+
}
136+
137+
func setUserInfo(userId: String?, userToken: String?, completion: @escaping () -> Void) {
138+
Task {
139+
await environment.setUserInfo(userId: userId, userToken: userToken)
140+
completion()
141+
}
142+
}
143+
144+
/// Returns the userId that was set from the Knock.shared.signIn method.
145+
func getUserId() async -> String? {
146+
await environment.getUserId()
147+
}
148+
149+
func getUserId(completion: @escaping (String?) -> Void) {
150+
Task {
151+
completion(await environment.getUserId())
152+
}
153+
}
154+
155+
func getDeviceToken() async -> String? {
156+
await environment.getDeviceToken()
157+
}
158+
159+
func getDeviceToken(completion: @escaping (String?) -> Void) {
160+
Task {
161+
completion(await environment.getDeviceToken())
162+
}
163+
}
164+
165+
func getPushChannelId() async -> String? {
166+
await environment.getPushChannelId()
167+
}
168+
169+
func getPushChannelId(completion: @escaping (String?) -> Void) {
170+
Task {
171+
completion(await environment.getPushChannelId())
172+
}
173+
}
174+
}

Sources/Modules/ChannelModule.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,11 @@ public extension Knock {
246246
- channelId: the id of the APNS channel
247247
- token: the APNS device token as a `String`
248248
*/
249-
func registerTokenForAPNS(channelId: String, token: String) async throws -> ChannelData {
249+
func registerTokenForAPNS(channelId: String?, token: String) async throws -> ChannelData {
250250
return try await self.channelModule.registerTokenForAPNS(channelId: channelId, token: token)
251251
}
252252

253-
func registerTokenForAPNS(channelId: String, token: String, completionHandler: @escaping ((Result<ChannelData, Error>) -> Void)) {
253+
func registerTokenForAPNS(channelId: String?, token: String, completionHandler: @escaping ((Result<ChannelData, Error>) -> Void)) {
254254
Task {
255255
do {
256256
let channelData = try await registerTokenForAPNS(channelId: channelId, token: token)

Sources/Modules/UserModule.swift

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,6 @@ internal class UserModule {
3636

3737
public extension Knock {
3838

39-
/// Returns the userId that was set from the Knock.shared.signIn method.
40-
func getUserId() async -> String? {
41-
await environment.getUserId()
42-
}
43-
44-
func getUserId(completion: @escaping (String?) -> Void) {
45-
Task {
46-
completion(await environment.getUserId())
47-
}
48-
}
49-
5039
/**
5140
Retrieve the current user, including all properties previously set.
5241
https://docs.knock.app/reference#get-user

0 commit comments

Comments
 (0)