Skip to content

Commit 481bde9

Browse files
committed
checking tokens when hydrate push sub
* Update check for 2 tokens being equal, since "" is equal to nil
1 parent 7eeecc2 commit 481bde9

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSUserRequests.swift

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class OSUserExecutor {
8080
let subscriptionObject = parseSubscriptionObjectResponse(response) {
8181
for subModel in subscriptionObject {
8282
if subModel["type"] as? String == "iOSPush",
83-
subModel["token"] as? String == originalPushToken {
83+
areTokensEqual(tokenA: originalPushToken, tokenB: subModel["token"] as? String) { // response may have "" token or no token
8484
OneSignalUserManagerImpl.sharedInstance.user.pushSubscriptionModel.hydrate(subModel)
8585
if let subId = subModel["id"] as? String {
8686
OSNotificationsManager.setPushSubscriptionId(subId)
@@ -130,6 +130,21 @@ class OSUserExecutor {
130130
}
131131
}
132132

133+
/**
134+
Returns if 2 tokens are equal. This is needed as a nil token is equal to the empty string "".
135+
*/
136+
static func areTokensEqual(tokenA: String?, tokenB: String?) -> Bool {
137+
// They are both strings or both nil
138+
if tokenA == tokenB {
139+
return true
140+
}
141+
// One is nil and the other is ""
142+
if (tokenA == nil && tokenB == "") || (tokenA == "" && tokenB == nil) {
143+
return true
144+
}
145+
return false
146+
}
147+
133148
static func parseSubscriptionObjectResponse(_ response: [AnyHashable: Any]?) -> [[String: Any]]? {
134149
return response?["subscriptions"] as? [[String: Any]]
135150
}

0 commit comments

Comments
 (0)