diff --git a/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSNewRecordsState.swift b/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSNewRecordsState.swift index 43ad3113c..2fc1e322f 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSNewRecordsState.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSNewRecordsState.swift @@ -54,11 +54,9 @@ public class OSNewRecordsState { } } - public func canAccess(_ key: String?) -> Bool { + public func canAccess(_ key: String) -> Bool { lock.withLock { - guard let key = key, - let timeLastMovedOrCreated = records[key] - else { + guard let timeLastMovedOrCreated = records[key] else { return true } diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Requests/OSRequestCreateUser.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Requests/OSRequestCreateUser.swift index e83785005..ef4e4a5e3 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Requests/OSRequestCreateUser.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Requests/OSRequestCreateUser.swift @@ -47,16 +47,21 @@ class OSRequestCreateUser: OneSignalRequest, OSUserRequest { /// Checks if the subscription ID can be accessed, if a subscription is being included in the request func prepareForExecution(newRecordsState: OSNewRecordsState) -> Bool { - guard let appId = OneSignalConfigManager.getAppId(), - newRecordsState.canAccess(pushSubscriptionModel?.subscriptionId) - else { + guard let appId = OneSignalConfigManager.getAppId() else { + OneSignalLog.onesignalLog(.LL_ERROR, message: "Cannot generate the create user request due to null app ID.") + return false + } + + if let subscriptionId = pushSubscriptionModel?.subscriptionId, + !newRecordsState.canAccess(subscriptionId) + { OneSignalLog.onesignalLog(.LL_DEBUG, message: "Cannot generate the create user request yet.") return false } + _ = self.addPushSubscriptionIdToAdditionalHeaders() self.addJWTHeader(identityModel: identityModel) self.path = "apps/\(appId)/users" - // The pushSub doesn't need to have a token. return true }