Skip to content

Commit b6a9073

Browse files
authored
Merge pull request #834 from Iterable/feature/MOB-9637-Add-handlers-for-notifying-customer-app-of-newly-created-Anon-userid
MOB-9637 add handlers for notifying customer app of newly created anon userid
2 parents eb28d3e + 0a91e58 commit b6a9073

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

sample-apps/swift-sample-app/swift-sample-app/AppDelegate.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
2727
config.customActionDelegate = self
2828
config.urlDelegate = self
2929
config.inAppDisplayInterval = 1
30-
30+
config.anonUserDelegate = self
3131
IterableAPI.initialize(apiKey: iterableApiKey,
3232
launchOptions: launchOptions,
3333
config: config)
@@ -157,6 +157,12 @@ extension AppDelegate: IterableURLDelegate {
157157
}
158158
}
159159

160+
extension AppDelegate: IterableAnonUserDelegate {
161+
func onAnonUserCreated(userId: String) {
162+
print("UserId Created from anonsession: \(userId)")
163+
}
164+
}
165+
160166
// MARK: IterableCustomActionDelegate
161167

162168
extension AppDelegate: IterableCustomActionDelegate {

swift-sdk/Internal/AnonymousUserManager.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ public class AnonymousUserManager: AnonymousUserManagerProtocol {
128128
}
129129

130130
self.localStorage.userIdAnnon = userId
131+
self.config.anonUserDelegate?.onAnonUserCreated(userId: userId)
131132
IterableAPI.implementation?.setUserId(userId, authToken: nil, successHandler: nil, failureHandler: nil, isAnon: true, identityResolution: nil)
132133
self.syncNonSyncedEvents()
133134
}

swift-sdk/IterableConfig.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ import Foundation
5858
@objc func onAuthFailure(_ authFailure: AuthFailure)
5959
}
6060

61+
/// The delegate for getting the UserId once annon session tracked
62+
@objc public protocol IterableAnonUserDelegate: AnyObject {
63+
@objc func onAnonUserCreated(userId: String)
64+
}
65+
6166
/// Iterable Configuration Object. Use this when initializing the API.
6267
@objcMembers
6368
public class IterableConfig: NSObject {
@@ -84,7 +89,11 @@ public class IterableConfig: NSObject {
8489

8590
/// Implement this protocol to enable token-based authentication with the Iterable SDK
8691
public weak var authDelegate: IterableAuthDelegate?
87-
92+
93+
/// Implement this protocol to get userId once the userId set for AnonUser
94+
public weak var anonUserDelegate: IterableAnonUserDelegate?
95+
96+
8897
/// When set to `true`, IterableSDK will automatically register and deregister
8998
/// notification tokens.
9099
public var autoPushRegistration = true

0 commit comments

Comments
 (0)