Skip to content

Commit 494fc17

Browse files
davidtruongtapashmajumder
authored andcommitted
Calls createUserId when the user logs in via a userId.
1 parent 4cc55e5 commit 494fc17

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

swift-sdk/ITBConsts.swift

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public extension String {
2626
public static let ITBL_PATH_TRACK_INAPP_CLICK = "events/trackInAppClick"
2727
public static let ITBL_PATH_TRACK_INAPP_OPEN = "events/trackInAppOpen"
2828
public static let ITBL_PATH_TRACK_PUSH_OPEN = "events/trackPushOpen"
29+
public static let ITBL_PATH_CREATE_USER = "users/createUserForUserId"
2930
public static let ITBL_PATH_UPDATE_USER = "users/update"
3031
public static let ITBL_PATH_UPDATE_EMAIL = "users/updateEmail"
3132
public static let ITBL_PATH_UPDATE_SUBSCRIPTIONS = "users/updateSubscriptions"

swift-sdk/Internal/IterableAPIInternal.swift

+16
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ final class IterableAPIInternal : NSObject, PushTrackerProtocol {
5353
_userId = newValue
5454
_email = nil
5555
storeEmailAndUserId()
56+
createUserId(onSuccess: IterableAPIInternal.defaultOnSucess(identifier: "createUserId"), onFailure: IterableAPIInternal.defaultOnFailure(identifier: "createUserId"))
5657

5758
enableDeviceForCurrentUser()
5859
}
@@ -220,6 +221,21 @@ final class IterableAPIInternal : NSObject, PushTrackerProtocol {
220221
onFailure: onFailure)
221222
}
222223
}
224+
225+
func createUserId(onSuccess: OnSuccessHandler?, onFailure: OnFailureHandler?) {
226+
guard userId != nil else {
227+
ITBError("UserId is nil")
228+
onFailure?("UserId is nil", nil)
229+
return
230+
}
231+
232+
var args = [AnyHashable : Any]()
233+
args[.ITBL_KEY_USER_ID] = userId
234+
235+
if let request = createPostRequest(forPath: .ITBL_PATH_CREATE_USER, withBody: args) {
236+
sendRequest(request, onSuccess: onSuccess, onFailure: onFailure)
237+
}
238+
}
223239

224240
func trackPurchase(_ total: NSNumber, items: [CommerceItem]) {
225241
trackPurchase(total, items: items, dataFields: nil)

swift-sdk/IterableConstants.h

-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,3 @@ typedef void (^OnSuccessHandler)(NSDictionary *data);
2222
The prototype for the completion handler block that gets called when an Iterable call fails
2323
*/
2424
typedef void (^OnFailureHandler)(NSString *reason, NSData *_Nullable data);
25-

0 commit comments

Comments
 (0)