diff --git a/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/Consistency/IamFetch/OSIamFetchReadyCondition.swift b/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/Consistency/IamFetch/OSIamFetchReadyCondition.swift index 3a5021eb2..b915de506 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/Consistency/IamFetch/OSIamFetchReadyCondition.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/Consistency/IamFetch/OSIamFetchReadyCondition.swift @@ -25,7 +25,7 @@ THE SOFTWARE. */ -@objc public class OSIamFetchReadyCondition: NSObject, OSCondition { +@objc public class OSIamFetchReadyCondition: NSObject, OSCondition { // the id used to index the token map (e.g. onesignalId) private let id: String private var hasSubscriptionUpdatePending: Bool = false @@ -48,11 +48,11 @@ // Expose the constant to Objective-C @objc public static let CONDITIONID: String = "OSIamFetchReadyCondition" - + public var conditionId: String { return OSIamFetchReadyCondition.CONDITIONID } - + public func setSubscriptionUpdatePending(value: Bool) { hasSubscriptionUpdatePending = value } @@ -63,12 +63,12 @@ let userCreateTokenSet = tokenMap[NSNumber(value: OSIamFetchOffsetKey.userCreate.rawValue)] != nil let userUpdateTokenSet = tokenMap[NSNumber(value: OSIamFetchOffsetKey.userUpdate.rawValue)] != nil let subscriptionTokenSet = tokenMap[NSNumber(value: OSIamFetchOffsetKey.subscriptionUpdate.rawValue)] != nil - - if (userCreateTokenSet) { - return true; + + if userCreateTokenSet { + return true } - if (hasSubscriptionUpdatePending) { + if hasSubscriptionUpdatePending { return userUpdateTokenSet && subscriptionTokenSet } return userUpdateTokenSet diff --git a/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/Consistency/OSConsistencyManager.swift b/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/Consistency/OSConsistencyManager.swift index 0f12f7397..ac7129de8 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/Consistency/OSConsistencyManager.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/Consistency/OSConsistencyManager.swift @@ -38,7 +38,7 @@ import OneSignalCore // Private initializer to prevent multiple instances private override init() {} - + // Used for testing public func reset() { indexedTokens = [:] @@ -72,13 +72,13 @@ import OneSignalCore return condition.getNewestToken(indexedTokens: self.indexedTokens) } } - + // Method to resolve conditions by condition ID (e.g. OSIamFetchReadyCondition.ID) @objc public func resolveConditionsWithID(id: String) { guard let conditionList = indexedConditions[id] else { return } var completedConditions: [(OSCondition, DispatchSemaphore)] = [] for (condition, semaphore) in conditionList { - if (condition.conditionId == id) { + if condition.conditionId == id { semaphore.signal() completedConditions.append((condition, semaphore)) } diff --git a/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/Consistency/OSReadYourWriteData.swift b/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/Consistency/OSReadYourWriteData.swift index a9cf045b2..287d660ca 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/Consistency/OSReadYourWriteData.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/Consistency/OSReadYourWriteData.swift @@ -57,4 +57,3 @@ public class OSReadYourWriteData: NSObject { return hasher.finalize() } } - diff --git a/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSOperationRepo.swift b/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSOperationRepo.swift index 2e280825f..8d85d17b0 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSOperationRepo.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSOperationRepo.swift @@ -118,7 +118,7 @@ public class OSOperationRepo: NSObject { // Persist the deltas (including new delta) to storage OneSignalUserDefaults.initShared().saveCodeableData(forKey: OS_OPERATION_REPO_DELTA_QUEUE_KEY, withValue: self.deltaQueue) - + if flush { self.flushDeltaQueue() } diff --git a/iOS_SDK/OneSignalSDK/OneSignalOSCoreMocks/MockNewRecordsState.swift b/iOS_SDK/OneSignalSDK/OneSignalOSCoreMocks/MockNewRecordsState.swift index 4a1c8d278..25a6444f7 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalOSCoreMocks/MockNewRecordsState.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalOSCoreMocks/MockNewRecordsState.swift @@ -42,10 +42,6 @@ public class MockNewRecordsState: OSNewRecordsState { super.add(key, overwrite) } - override public func canAccess(_ key: String) -> Bool { - return super.canAccess(key) - } - public func get(_ key: String?) -> [MockNewRecord] { return records.filter { $0.key == key } } diff --git a/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OSConsistencyManagerTests.swift b/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OSConsistencyManagerTests.swift index 215c298f9..9a686d644 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OSConsistencyManagerTests.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OSConsistencyManagerTests.swift @@ -121,7 +121,7 @@ class OSConsistencyManagerTests: XCTestCase { XCTAssertTrue(true) // Simulate some async action completing without hanging } } - + func testSetRywTokenWithoutAnyCondition() { // Given let id = "test_id" @@ -138,7 +138,7 @@ class OSConsistencyManagerTests: XCTestCase { // There is no condition registered, so we just check that no errors occur XCTAssertTrue(true) // If no errors occur, this test will pass } - + func testMultipleConditionsWithDifferentKeys() { let expectation1 = self.expectation(description: "UserUpdate condition met") let expectation2 = self.expectation(description: "SubscriptionUpdate condition met") @@ -215,7 +215,7 @@ class OSConsistencyManagerTests: XCTestCase { return result } - + func testConditionMetImmediatelyAfterTokenAlreadySet() { let expectation = self.expectation(description: "Condition met immediately") @@ -247,7 +247,7 @@ class OSConsistencyManagerTests: XCTestCase { waitForExpectations(timeout: 2.0, handler: nil) } - + func testConcurrentUpdatesToTokens() { let expectation = self.expectation(description: "Concurrent updates handled correctly") @@ -294,16 +294,15 @@ class OSConsistencyManagerTests: XCTestCase { } } - // Mock implementation of OSCondition that simulates a condition that isn't met class TestUnmetCondition: NSObject, OSCondition { // class-level constant for the ID public static let CONDITIONID = "TestUnmetCondition" - + public var conditionId: String { return TestUnmetCondition.CONDITIONID } - + func isMet(indexedTokens: [String: [NSNumber: OSReadYourWriteData]]) -> Bool { return false // Always returns false to simulate an unmet condition } @@ -316,49 +315,49 @@ class TestUnmetCondition: NSObject, OSCondition { // Mock implementation of OSCondition for cases where the condition is met class TestMetCondition: NSObject, OSCondition { private let expectedTokens: [String: [NSNumber: OSReadYourWriteData]] - + // class-level constant for the ID public static let CONDITIONID = "TestMetCondition" - + public var conditionId: String { return TestMetCondition.CONDITIONID } - + init(expectedTokens: [String: [NSNumber: OSReadYourWriteData]]) { self.expectedTokens = expectedTokens } - + func isMet(indexedTokens: [String: [NSNumber: OSReadYourWriteData]]) -> Bool { print("Expected tokens: \(expectedTokens)") print("Actual tokens: \(indexedTokens)") - + // Check if all the expected tokens are present in the actual tokens for (id, expectedTokenMap) in expectedTokens { guard let actualTokenMap = indexedTokens[id] else { print("No tokens found for id: \(id)") return false } - + // Check if all expected keys (e.g., userUpdate, subscriptionUpdate) are present with the correct value for (expectedKey, expectedValue) in expectedTokenMap { guard let actualValue = actualTokenMap[expectedKey] else { print("Key \(expectedKey) not found in actual tokens") return false } - + if actualValue != expectedValue { print("Mismatch for key \(expectedKey): expected \(expectedValue.rywToken), found \(actualValue.rywToken)") return false } } } - + print("Condition met for id") return true } - + func getNewestToken(indexedTokens: [String: [NSNumber: OSReadYourWriteData]]) -> OSReadYourWriteData? { - var dataBasedOnNewestRywToken: OSReadYourWriteData? = nil + var dataBasedOnNewestRywToken: OSReadYourWriteData? // Loop through the token maps and compare the values for tokenMap in indexedTokens.values { diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Executors/OSPropertyOperationExecutor.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Executors/OSPropertyOperationExecutor.swift index 74ad0826c..a8dc7c072 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Executors/OSPropertyOperationExecutor.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Executors/OSPropertyOperationExecutor.swift @@ -259,7 +259,7 @@ class OSPropertyOperationExecutor: OSOperationExecutor { if let rywToken = response?["ryw_token"] as? String { let rywDelay = response?["ryw_delay"] as? NSNumber - + OSConsistencyManager.shared.setRywTokenAndDelay( id: onesignalId, key: OSIamFetchOffsetKey.userUpdate, diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Executors/OSSubscriptionOperationExecutor.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Executors/OSSubscriptionOperationExecutor.swift index 2ef43dafc..090c43dd7 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Executors/OSSubscriptionOperationExecutor.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Executors/OSSubscriptionOperationExecutor.swift @@ -297,7 +297,7 @@ class OSSubscriptionOperationExecutor: OSOperationExecutor { } return } - + if let onesignalId = request.identityModel.onesignalId { if let rywToken = response["ryw_token"] as? String { @@ -312,7 +312,7 @@ class OSSubscriptionOperationExecutor: OSOperationExecutor { OSConsistencyManager.shared.resolveConditionsWithID(id: OSIamFetchReadyCondition.CONDITIONID) } } - + request.subscriptionModel.hydrate(response) if inBackground { OSBackgroundTaskManager.endBackgroundTask(backgroundTaskIdentifier) @@ -419,7 +419,7 @@ class OSSubscriptionOperationExecutor: OSOperationExecutor { OSBackgroundTaskManager.endBackgroundTask(backgroundTaskIdentifier) } } - + if let onesignalId = OneSignalUserManagerImpl.sharedInstance.onesignalId { if let rywToken = response?["ryw_token"] as? String { diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Executors/OSUserExecutor.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Executors/OSUserExecutor.swift index 2bc072dcb..3ca2e4c39 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Executors/OSUserExecutor.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Executors/OSUserExecutor.swift @@ -258,7 +258,7 @@ extension OSUserExecutor { } else { self.executePendingRequests() } - + if let onesignalId = request.identityModel.onesignalId { if let rywToken = response["ryw_token"] as? String { diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSSubscriptionModelStoreListener.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSSubscriptionModelStoreListener.swift index d633e5e38..a58b1ac95 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSSubscriptionModelStoreListener.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSSubscriptionModelStoreListener.swift @@ -70,7 +70,7 @@ class OSSubscriptionModelStoreListener: OSModelStoreListener { let condition = OSIamFetchReadyCondition.sharedInstance(withId: onesignalId) condition.setSubscriptionUpdatePending(value: true) } - + return OSDelta( name: OS_UPDATE_SUBSCRIPTION_DELTA, identityModelId: OneSignalUserManagerImpl.sharedInstance.user.identityModel.modelId, diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift index 710d3724b..d1ad50a08 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift @@ -529,7 +529,7 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager { guard let externalId = user.identityModel.externalId, let jwtExpiredHandler = self.jwtExpiredHandler else { return } - jwtExpiredHandler(externalId) { [self] (newToken) -> Void in + jwtExpiredHandler(externalId) { [self] (newToken) in guard user.identityModel.externalId == externalId else { return } diff --git a/iOS_SDK/OneSignalSDK/OneSignalUserTests/OneSignalUserTests.swift b/iOS_SDK/OneSignalSDK/OneSignalUserTests/OneSignalUserTests.swift index 5e5673676..9165e31d7 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUserTests/OneSignalUserTests.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUserTests/OneSignalUserTests.swift @@ -87,7 +87,7 @@ final class OneSignalUserTests: XCTestCase { /* When */ OneSignalUserManagerImpl.sharedInstance.sendSessionTime(100) - + OneSignalUserManagerImpl.sharedInstance.updatePropertiesDeltas(property: .session_count, value: 1, flush: false) OneSignalUserManagerImpl.sharedInstance.setLanguage("lang_1") @@ -106,7 +106,6 @@ final class OneSignalUserTests: XCTestCase { OneSignalUserManagerImpl.sharedInstance.addTags(["a": "a", "b": "b", "c": "c"]) - let purchases = [ ["sku": "sku1", "amount": "1.25", "iso": "USD"], ["sku": "sku2", "amount": "3.99", "iso": "USD"] @@ -115,7 +114,7 @@ final class OneSignalUserTests: XCTestCase { OneSignalUserManagerImpl.sharedInstance.sendPurchases(purchases as [[String: AnyObject]]) OneSignalUserManagerImpl.sharedInstance.setLocation(latitude: 111.111, longitude: 222.222) - + // This adds a `session_count` property with value of 1 // It also sets `refresh_device_metadata` to `true` OneSignalUserManagerImpl.sharedInstance.startNewSession()