Skip to content

Commit 529a148

Browse files
committed
Make NewRecordsState method non-optional
* The canAccess method should really check a non-optional string * Adjust the use of this method at the calling site
1 parent f06048f commit 529a148

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSNewRecordsState.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,9 @@ public class OSNewRecordsState {
5454
}
5555
}
5656

57-
public func canAccess(_ key: String?) -> Bool {
57+
public func canAccess(_ key: String) -> Bool {
5858
lock.withLock {
59-
guard let key = key,
60-
let timeLastMovedOrCreated = records[key]
61-
else {
59+
guard let timeLastMovedOrCreated = records[key] else {
6260
return true
6361
}
6462

iOS_SDK/OneSignalSDK/OneSignalUser/Source/Requests/OSRequestCreateUser.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,21 @@ class OSRequestCreateUser: OneSignalRequest, OSUserRequest {
4747

4848
/// Checks if the subscription ID can be accessed, if a subscription is being included in the request
4949
func prepareForExecution(newRecordsState: OSNewRecordsState) -> Bool {
50-
guard let appId = OneSignalConfigManager.getAppId(),
51-
newRecordsState.canAccess(pushSubscriptionModel?.subscriptionId)
52-
else {
50+
guard let appId = OneSignalConfigManager.getAppId() else {
51+
OneSignalLog.onesignalLog(.LL_ERROR, message: "Cannot generate the create user request due to null app ID.")
52+
return false
53+
}
54+
55+
if let subscriptionId = pushSubscriptionModel?.subscriptionId,
56+
!newRecordsState.canAccess(subscriptionId)
57+
{
5358
OneSignalLog.onesignalLog(.LL_DEBUG, message: "Cannot generate the create user request yet.")
5459
return false
5560
}
61+
5662
_ = self.addPushSubscriptionIdToAdditionalHeaders()
5763
self.addJWTHeader(identityModel: identityModel)
5864
self.path = "apps/\(appId)/users"
59-
// The pushSub doesn't need to have a token.
6065
return true
6166
}
6267

0 commit comments

Comments
 (0)