From 2228ed76c01f37469dd8f7f83b1dcf68b4102c96 Mon Sep 17 00:00:00 2001 From: Nan Date: Thu, 7 Dec 2023 12:49:03 -0800 Subject: [PATCH] swiftlint --- .../Source/OSOperationRepo.swift | 10 ++-- .../Source/OSIdentityModel.swift | 8 +-- .../Source/OSIdentityOperationExecutor.swift | 20 ++++---- .../Source/OSPropertiesModel.swift | 4 +- .../Source/OSPropertyOperationExecutor.swift | 14 +++--- .../Source/OSSubscriptionModel.swift | 22 ++++---- .../OSSubscriptionOperationExecutor.swift | 30 +++++------ .../OneSignalUser/Source/OSUserRequests.swift | 50 +++++++++---------- .../Source/OneSignalUserManagerImpl.swift | 37 +++++++------- .../Source/OneSignalSwiftInterface.swift | 18 +++---- 10 files changed, 105 insertions(+), 108 deletions(-) diff --git a/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSOperationRepo.swift b/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSOperationRepo.swift index 8f9e8f77b..25ef3b00f 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSOperationRepo.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSOperationRepo.swift @@ -113,12 +113,12 @@ public class OSOperationRepo: NSObject { OneSignalLog.onesignalLog(.LL_DEBUG, message: "OSOperationRepo not flushing queue due to being paused") return } - + guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: nil) else { return } - - if (inBackground) { + + if inBackground { OSBackgroundTaskManager.beginBackgroundTask(OPERATION_REPO_BACKGROUND_TASK) } @@ -148,8 +148,8 @@ public class OSOperationRepo: NSObject { for executor in executors { executor.processDeltaQueue(inBackground: inBackground) } - - if (inBackground) { + + if inBackground { OSBackgroundTaskManager.endBackgroundTask(OPERATION_REPO_BACKGROUND_TASK) } diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSIdentityModel.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSIdentityModel.swift index 63b239368..b915030cc 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSIdentityModel.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSIdentityModel.swift @@ -92,7 +92,7 @@ class OSIdentityModel: OSModel { OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OSIdentityModel hydrateModel()") var newOnesignalId: String? var newExternalId: String? - + for property in response { switch property.key { case "external_id": @@ -108,18 +108,18 @@ class OSIdentityModel: OSModel { } fireUserStateChanged(newOnesignalId: newOnesignalId, newExternalId: newExternalId) } - + /** Fires the user observer if `onesignal_id` OR `external_id` has changed from the previous snapshot (previous hydration). */ private func fireUserStateChanged(newOnesignalId: String?, newExternalId: String?) { let prevOnesignalId = OneSignalUserDefaults.initShared().getSavedString(forKey: OS_SNAPSHOT_ONESIGNAL_ID, defaultValue: nil) let prevExternalId = OneSignalUserDefaults.initShared().getSavedString(forKey: OS_SNAPSHOT_EXTERNAL_ID, defaultValue: nil) - + guard prevOnesignalId != newOnesignalId || prevExternalId != newExternalId else { return } - + OneSignalUserDefaults.initShared().saveString(forKey: OS_SNAPSHOT_ONESIGNAL_ID, withValue: newOnesignalId) OneSignalUserDefaults.initShared().saveString(forKey: OS_SNAPSHOT_EXTERNAL_ID, withValue: newExternalId) diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSIdentityOperationExecutor.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSIdentityOperationExecutor.swift index c49ef5c7b..475ddffde 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSIdentityOperationExecutor.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSIdentityOperationExecutor.swift @@ -175,16 +175,16 @@ class OSIdentityOperationExecutor: OSOperationExecutor { OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OSIdentityOperationExecutor: executeAddAliasesRequest making request: \(request)") let backgroundTaskIdentifier = IDENTITY_EXECUTOR_BACKGROUND_TASK + UUID().uuidString - if (inBackground) { + if inBackground { OSBackgroundTaskManager.beginBackgroundTask(backgroundTaskIdentifier) } - + OneSignalClient.shared().execute(request) { _ in // No hydration from response // On success, remove request from cache self.addRequestQueue.removeAll(where: { $0 == request}) OneSignalUserDefaults.initShared().saveCodeableData(forKey: OS_IDENTITY_EXECUTOR_ADD_REQUEST_QUEUE_KEY, withValue: self.addRequestQueue) - if (inBackground) { + if inBackground { OSBackgroundTaskManager.endBackgroundTask(backgroundTaskIdentifier) } } onFailure: { error in @@ -198,7 +198,7 @@ class OSIdentityOperationExecutor: OSOperationExecutor { // Logout if the user in the SDK is the same guard OneSignalUserManagerImpl.sharedInstance.isCurrentUser(request.identityModel) else { - if (inBackground) { + if inBackground { OSBackgroundTaskManager.endBackgroundTask(backgroundTaskIdentifier) } return @@ -212,7 +212,7 @@ class OSIdentityOperationExecutor: OSOperationExecutor { OneSignalUserDefaults.initShared().saveCodeableData(forKey: OS_IDENTITY_EXECUTOR_ADD_REQUEST_QUEUE_KEY, withValue: self.addRequestQueue) } } - if (inBackground) { + if inBackground { OSBackgroundTaskManager.endBackgroundTask(backgroundTaskIdentifier) } } @@ -230,21 +230,21 @@ class OSIdentityOperationExecutor: OSOperationExecutor { OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OSIdentityOperationExecutor: executeRemoveAliasRequest making request: \(request)") let backgroundTaskIdentifier = IDENTITY_EXECUTOR_BACKGROUND_TASK + UUID().uuidString - if (inBackground) { + if inBackground { OSBackgroundTaskManager.beginBackgroundTask(backgroundTaskIdentifier) } - + OneSignalClient.shared().execute(request) { _ in // There is nothing to hydrate // On success, remove request from cache self.removeRequestQueue.removeAll(where: { $0 == request}) OneSignalUserDefaults.initShared().saveCodeableData(forKey: OS_IDENTITY_EXECUTOR_REMOVE_REQUEST_QUEUE_KEY, withValue: self.removeRequestQueue) - if (inBackground) { + if inBackground { OSBackgroundTaskManager.endBackgroundTask(backgroundTaskIdentifier) } } onFailure: { error in OneSignalLog.onesignalLog(.LL_ERROR, message: "OSIdentityOperationExecutor remove alias request failed with error: \(error.debugDescription)") - + if let nsError = error as? NSError { let responseType = OSNetworkingUtils.getResponseStatusType(nsError.code) if responseType != .retryable { @@ -254,7 +254,7 @@ class OSIdentityOperationExecutor: OSOperationExecutor { OneSignalUserDefaults.initShared().saveCodeableData(forKey: OS_IDENTITY_EXECUTOR_REMOVE_REQUEST_QUEUE_KEY, withValue: self.removeRequestQueue) } } - if (inBackground) { + if inBackground { OSBackgroundTaskManager.endBackgroundTask(backgroundTaskIdentifier) } } diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSPropertiesModel.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSPropertiesModel.swift index ce35d9eb2..eb9e59bc1 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSPropertiesModel.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSPropertiesModel.swift @@ -78,9 +78,9 @@ class OSPropertiesModel: OSModel { self.set(property: "location", newValue: location) } } - + var timezoneId = TimeZone.current.identifier - + var tags: [String: String] = [:] // MARK: - Initialization diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSPropertyOperationExecutor.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSPropertyOperationExecutor.swift index 3c3e5b2b9..9f219f6dd 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSPropertyOperationExecutor.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSPropertyOperationExecutor.swift @@ -132,18 +132,18 @@ class OSPropertyOperationExecutor: OSOperationExecutor { return } request.sentToClient = true - + let backgroundTaskIdentifier = PROPERTIES_EXECUTOR_BACKGROUND_TASK + UUID().uuidString - if (inBackground) { + if inBackground { OSBackgroundTaskManager.beginBackgroundTask(backgroundTaskIdentifier) } - + OneSignalClient.shared().execute(request) { _ in // On success, remove request from cache, and we do need to hydrate // TODO: We need to hydrate after all ? What why ? self.updateRequestQueue.removeAll(where: { $0 == request}) OneSignalUserDefaults.initShared().saveCodeableData(forKey: OS_PROPERTIES_EXECUTOR_UPDATE_REQUEST_QUEUE_KEY, withValue: self.updateRequestQueue) - if (inBackground) { + if inBackground { OSBackgroundTaskManager.endBackgroundTask(backgroundTaskIdentifier) } } onFailure: { error in @@ -157,7 +157,7 @@ class OSPropertyOperationExecutor: OSOperationExecutor { // Logout if the user in the SDK is the same guard OneSignalUserManagerImpl.sharedInstance.isCurrentUser(request.identityModel) else { - if (inBackground) { + if inBackground { OSBackgroundTaskManager.endBackgroundTask(backgroundTaskIdentifier) } return @@ -171,7 +171,7 @@ class OSPropertyOperationExecutor: OSOperationExecutor { OneSignalUserDefaults.initShared().saveCodeableData(forKey: OS_PROPERTIES_EXECUTOR_UPDATE_REQUEST_QUEUE_KEY, withValue: self.updateRequestQueue) } } - if (inBackground) { + if inBackground { OSBackgroundTaskManager.endBackgroundTask(backgroundTaskIdentifier) } } @@ -189,7 +189,7 @@ extension OSPropertyOperationExecutor { modelToUpdate: propertiesModel, identityModel: identityModel) - if (sendImmediately) { + if sendImmediately { // Bypass the request queues OneSignalClient.shared().execute(request) { _ in if let onSuccess = onSuccess { diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSSubscriptionModel.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSSubscriptionModel.swift index 805e224b7..89471da2c 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSSubscriptionModel.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSSubscriptionModel.swift @@ -203,7 +203,7 @@ class OSSubscriptionModel: OSModel { self.set(property: "testType", newValue: testType) } } - + var deviceOs = UIDevice.current.systemVersion { didSet { guard deviceOs != oldValue else { @@ -212,7 +212,7 @@ class OSSubscriptionModel: OSModel { self.set(property: "deviceOs", newValue: deviceOs) } } - + var sdk = ONESIGNAL_VERSION { didSet { guard sdk != oldValue else { @@ -221,7 +221,7 @@ class OSSubscriptionModel: OSModel { self.set(property: "sdk", newValue: sdk) } } - + var deviceModel: String? = OSDeviceUtils.getDeviceVariant() { didSet { guard deviceModel != oldValue else { @@ -230,7 +230,7 @@ class OSSubscriptionModel: OSModel { self.set(property: "deviceModel", newValue: deviceModel) } } - + var appVersion: String? = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String { didSet { guard appVersion != oldValue else { @@ -239,7 +239,7 @@ class OSSubscriptionModel: OSModel { self.set(property: "appVersion", newValue: appVersion) } } - + var netType: Int? = OSNetworkingUtils.getNetType() as? Int { didSet { guard netType != oldValue else { @@ -266,7 +266,7 @@ class OSSubscriptionModel: OSModel { if type == .push { let releaseMode: OSUIApplicationReleaseMode = OneSignalMobileProvision.releaseMode() #if targetEnvironment(simulator) - if (releaseMode == OSUIApplicationReleaseMode.UIApplicationReleaseUnknown) { + if releaseMode == OSUIApplicationReleaseMode.UIApplicationReleaseUnknown { self.testType = OSUIApplicationReleaseMode.UIApplicationReleaseDev.rawValue } #endif @@ -322,7 +322,7 @@ class OSSubscriptionModel: OSModel { self.deviceModel = coder.decodeObject(forKey: "deviceModel") as? String self.appVersion = coder.decodeObject(forKey: "appVersion") as? String self.netType = coder.decodeObject(forKey: "netType") as? Int - + super.init(coder: coder) } @@ -354,7 +354,7 @@ class OSSubscriptionModel: OSModel { } } } - + // Using snake_case so we can use this in request bodies public func jsonRepresentation() -> [String: Any] { var json: [String: Any] = [:] @@ -401,7 +401,7 @@ extension OSSubscriptionModel { func updateNotificationTypes() { notificationTypes = Int(OSNotificationsManager.getNotificationTypes(_isDisabled)) } - + func updateTestType() { let releaseMode: OSUIApplicationReleaseMode = OneSignalMobileProvision.releaseMode() // Workaround to unsure how to extract the Int value in 1 step... @@ -415,7 +415,7 @@ extension OSSubscriptionModel { self.testType = OSUIApplicationReleaseMode.UIApplicationReleaseWildcard.rawValue } } - + func update() { updateTestType() deviceOs = UIDevice.current.systemVersion @@ -429,7 +429,7 @@ extension OSSubscriptionModel { OneSignalUserDefaults.initShared().saveString(forKey: OSUD_PUSH_SUBSCRIPTION_ID, withValue: subscriptionId) } } - + enum OSPushPropertyChanged { case subscriptionId(String?) case reachable(Bool) diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSSubscriptionOperationExecutor.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSSubscriptionOperationExecutor.swift index 0541ba27c..8188663ef 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSSubscriptionOperationExecutor.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSSubscriptionOperationExecutor.swift @@ -241,10 +241,10 @@ class OSSubscriptionOperationExecutor: OSOperationExecutor { request.sentToClient = true let backgroundTaskIdentifier = SUBSCRIPTION_EXECUTOR_BACKGROUND_TASK + UUID().uuidString - if (inBackground) { + if inBackground { OSBackgroundTaskManager.beginBackgroundTask(backgroundTaskIdentifier) } - + OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OSSubscriptionOperationExecutor: executeCreateSubscriptionRequest making request: \(request)") OneSignalClient.shared().execute(request) { result in // On success, remove request from cache (even if not hydrating model), and hydrate model @@ -253,13 +253,13 @@ class OSSubscriptionOperationExecutor: OSOperationExecutor { guard let response = result?["subscription"] as? [String: Any] else { OneSignalLog.onesignalLog(.LL_ERROR, message: "Unabled to parse response to create subscription request") - if (inBackground) { + if inBackground { OSBackgroundTaskManager.endBackgroundTask(backgroundTaskIdentifier) } return } request.subscriptionModel.hydrate(response) - if (inBackground) { + if inBackground { OSBackgroundTaskManager.endBackgroundTask(backgroundTaskIdentifier) } } onFailure: { error in @@ -272,7 +272,7 @@ class OSSubscriptionOperationExecutor: OSOperationExecutor { // Logout if the user in the SDK is the same guard OneSignalUserManagerImpl.sharedInstance.isCurrentUser(request.identityModel) else { - if (inBackground) { + if inBackground { OSBackgroundTaskManager.endBackgroundTask(backgroundTaskIdentifier) } return @@ -286,7 +286,7 @@ class OSSubscriptionOperationExecutor: OSOperationExecutor { OneSignalUserDefaults.initShared().saveCodeableData(forKey: OS_SUBSCRIPTION_EXECUTOR_ADD_REQUEST_QUEUE_KEY, withValue: self.addRequestQueue) } } - if (inBackground) { + if inBackground { OSBackgroundTaskManager.endBackgroundTask(backgroundTaskIdentifier) } } @@ -300,12 +300,12 @@ class OSSubscriptionOperationExecutor: OSOperationExecutor { return } request.sentToClient = true - + let backgroundTaskIdentifier = SUBSCRIPTION_EXECUTOR_BACKGROUND_TASK + UUID().uuidString - if (inBackground) { + if inBackground { OSBackgroundTaskManager.beginBackgroundTask(backgroundTaskIdentifier) } - + // This request can be executed as-is. OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OSSubscriptionOperationExecutor: executeDeleteSubscriptionRequest making request: \(request)") OneSignalClient.shared().execute(request) { _ in @@ -313,7 +313,7 @@ class OSSubscriptionOperationExecutor: OSOperationExecutor { // For example, if app restarts and we read in operations between sending this off and getting the response self.removeRequestQueue.removeAll(where: { $0 == request}) OneSignalUserDefaults.initShared().saveCodeableData(forKey: OS_SUBSCRIPTION_EXECUTOR_REMOVE_REQUEST_QUEUE_KEY, withValue: self.removeRequestQueue) - if (inBackground) { + if inBackground { OSBackgroundTaskManager.endBackgroundTask(backgroundTaskIdentifier) } } onFailure: { error in @@ -327,7 +327,7 @@ class OSSubscriptionOperationExecutor: OSOperationExecutor { OneSignalUserDefaults.initShared().saveCodeableData(forKey: OS_SUBSCRIPTION_EXECUTOR_REMOVE_REQUEST_QUEUE_KEY, withValue: self.removeRequestQueue) } } - if (inBackground) { + if inBackground { OSBackgroundTaskManager.endBackgroundTask(backgroundTaskIdentifier) } } @@ -343,16 +343,16 @@ class OSSubscriptionOperationExecutor: OSOperationExecutor { request.sentToClient = true let backgroundTaskIdentifier = SUBSCRIPTION_EXECUTOR_BACKGROUND_TASK + UUID().uuidString - if (inBackground) { + if inBackground { OSBackgroundTaskManager.beginBackgroundTask(backgroundTaskIdentifier) } - + OneSignalClient.shared().execute(request) { _ in // On success, remove request from cache. No model hydration occurs. // For example, if app restarts and we read in operations between sending this off and getting the response self.updateRequestQueue.removeAll(where: { $0 == request}) OneSignalUserDefaults.initShared().saveCodeableData(forKey: OS_SUBSCRIPTION_EXECUTOR_UPDATE_REQUEST_QUEUE_KEY, withValue: self.updateRequestQueue) - if (inBackground) { + if inBackground { OSBackgroundTaskManager.endBackgroundTask(backgroundTaskIdentifier) } } onFailure: { error in @@ -365,7 +365,7 @@ class OSSubscriptionOperationExecutor: OSOperationExecutor { OneSignalUserDefaults.initShared().saveCodeableData(forKey: OS_SUBSCRIPTION_EXECUTOR_UPDATE_REQUEST_QUEUE_KEY, withValue: self.updateRequestQueue) } } - if (inBackground) { + if inBackground { OSBackgroundTaskManager.endBackgroundTask(backgroundTaskIdentifier) } } diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSUserRequests.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSUserRequests.swift index 9c901c5a0..fa3db6791 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSUserRequests.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSUserRequests.swift @@ -58,7 +58,7 @@ class OSUserExecutor { identityModels[req.identityModel.modelId] = req.identityModel } userRequestQueue.append(req) - + } else if request.isKind(of: OSRequestCreateUser.self), let req = request as? OSRequestCreateUser { if let identityModel = OneSignalUserManagerImpl.sharedInstance.identityModelStore.getModel(modelId: req.identityModel.modelId) { // 1. The model exist in the store, set it to be the Request's model @@ -157,7 +157,7 @@ class OSUserExecutor { if !request.prepareForExecution() { return } - + if request.isKind(of: OSRequestFetchIdentityBySubscription.self), let fetchIdentityRequest = request as? OSRequestFetchIdentityBySubscription { executeFetchIdentityBySubscriptionRequest(fetchIdentityRequest) return @@ -210,7 +210,7 @@ class OSUserExecutor { } } } - + // Check if the current user is the same as the one in the request // If user has changed, don't hydrate, except for push subscription above guard OneSignalUserManagerImpl.sharedInstance.isCurrentUser(identityModel) else { @@ -343,14 +343,14 @@ class OSUserExecutor { } } } - + static func fetchIdentityBySubscription(_ user: OSUserInternal) { let request = OSRequestFetchIdentityBySubscription(identityModel: user.identityModel, pushSubscriptionModel: user.pushSubscriptionModel) - + appendToQueue(request) executePendingRequests() } - + /** For migrating legacy players from 3.x to 5.x. This request will fetch the identity object for a subscription ID, and we will use the returned onesignalId to fetch and hydrate the local user. */ @@ -365,19 +365,18 @@ class OSUserExecutor { OneSignalClient.shared().execute(request) { response in removeFromQueue(request) - + if let identityObject = parseIdentityObjectResponse(response), - let onesignalId = identityObject[OS_ONESIGNAL_ID] - { + let onesignalId = identityObject[OS_ONESIGNAL_ID] { request.identityModel.hydrate(identityObject) - + // Fetch this user's data if it is the current user guard OneSignalUserManagerImpl.sharedInstance.isCurrentUser(request.identityModel) else { executePendingRequests() return } - + fetchUser(aliasLabel: OS_ONESIGNAL_ID, aliasId: onesignalId, identityModel: request.identityModel) } } onFailure: { error in @@ -393,7 +392,7 @@ class OSUserExecutor { executePendingRequests() } } - + static func identifyUser(externalId: String, identityModelToIdentify: OSIdentityModel, identityModelToUpdate: OSIdentityModel) { let request = OSRequestIdentifyUser( aliasLabel: OS_EXTERNAL_ID, @@ -530,13 +529,12 @@ class OSUserExecutor { // Clear local data in preparation for hydration OneSignalUserManagerImpl.sharedInstance.clearUserData() parseFetchUserResponse(response: response, identityModel: request.identityModel, originalPushToken: OneSignalUserManagerImpl.sharedInstance.pushSubscriptionImpl.token) - + // If this is a on-new-session's fetch user call, check that the subscription still exists if request.onNewSession, OneSignalUserManagerImpl.sharedInstance.isCurrentUser(request.identityModel), let subId = OneSignalUserManagerImpl.sharedInstance.pushSubscriptionModel?.subscriptionId, - let subscriptionObjects = parseSubscriptionObjectResponse(response) - { + let subscriptionObjects = parseSubscriptionObjectResponse(response) { var subscriptionExists = false for subModel in subscriptionObjects { if subModel["id"] as? String == subId { @@ -544,7 +542,7 @@ class OSUserExecutor { break } } - + if !subscriptionExists { // This subscription probably has been deleted OneSignalLog.onesignalLog(.LL_ERROR, message: "OSUserExecutor.executeFetchUserRequest found this device's push subscription gone, now send the push subscription to server.") @@ -685,20 +683,20 @@ class OSRequestCreateUser: OneSignalRequest, OSUserRequest { class OSRequestFetchIdentityBySubscription: OneSignalRequest, OSUserRequest { var sentToClient = false let stringDescription: String - + override var description: String { return stringDescription } - + var identityModel: OSIdentityModel var pushSubscriptionModel: OSSubscriptionModel - + func prepareForExecution() -> Bool { guard let appId = OneSignalConfigManager.getAppId() else { OneSignalLog.onesignalLog(.LL_DEBUG, message: "Cannot generate the FetchIdentityBySubscription request due to null app ID.") return false } - + if let subscriptionId = pushSubscriptionModel.subscriptionId { self.path = "apps/\(appId)/subscriptions/\(subscriptionId)/user/identity" return true @@ -709,7 +707,7 @@ class OSRequestFetchIdentityBySubscription: OneSignalRequest, OSUserRequest { return false } } - + init(identityModel: OSIdentityModel, pushSubscriptionModel: OSSubscriptionModel) { self.identityModel = identityModel self.pushSubscriptionModel = pushSubscriptionModel @@ -717,14 +715,14 @@ class OSRequestFetchIdentityBySubscription: OneSignalRequest, OSUserRequest { super.init() self.method = GET } - + func encode(with coder: NSCoder) { coder.encode(identityModel, forKey: "identityModel") coder.encode(pushSubscriptionModel, forKey: "pushSubscriptionModel") coder.encode(method.rawValue, forKey: "method") // Encodes as String coder.encode(timestamp, forKey: "timestamp") } - + required init?(coder: NSCoder) { guard let identityModel = coder.decodeObject(forKey: "identityModel") as? OSIdentityModel, @@ -737,7 +735,7 @@ class OSRequestFetchIdentityBySubscription: OneSignalRequest, OSUserRequest { } self.identityModel = identityModel self.pushSubscriptionModel = pushSubscriptionModel - + self.stringDescription = "OSRequestFetchIdentityBySubscription with subscriptionId: \(pushSubscriptionModel.subscriptionId ?? "nil")" super.init() self.method = HTTPMethod(rawValue: rawMethod) @@ -847,7 +845,7 @@ class OSRequestFetchUser: OneSignalRequest, OSUserRequest { let aliasLabel: String let aliasId: String let onNewSession: Bool - + func prepareForExecution() -> Bool { guard let appId = OneSignalConfigManager.getAppId() else { OneSignalLog.onesignalLog(.LL_DEBUG, message: "Cannot generate the fetch user request due to null app ID.") @@ -910,7 +908,7 @@ class OSRequestAddAliases: OneSignalRequest, OSUserRequest { var identityModel: OSIdentityModel let aliases: [String: String] - + // requires a `onesignal_id` to send this request func prepareForExecution() -> Bool { if let onesignalId = identityModel.onesignalId, let appId = OneSignalConfigManager.getAppId() { diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift index e158992b2..77ff41530 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift @@ -104,7 +104,7 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager { var pushSubscriptionModel: OSSubscriptionModel? { return pushSubscriptionModelStore.getModel(key: OS_PUSH_SUBSCRIPTION_MODEL_KEY) } - + @objc public var pushSubscriptionId: String? { return _user?.pushSubscriptionModel.subscriptionId } @@ -112,7 +112,7 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager { @objc public var language: String? { return _user?.propertiesModel.language } - + @objc public let pushSubscriptionImpl: OSPushSubscriptionImpl private var hasCalledStart = false @@ -200,7 +200,7 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager { OSNotificationsManager.delegate = self var hasCachedUser = false - + // Path 1. Load user from cache, if any // Corrupted state if any of these models exist without the others if let identityModel = identityModelStore.getModels()[OS_IDENTITY_MODEL_KEY], @@ -270,14 +270,14 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager { private func createUserFromLegacyPlayer(_ playerId: String) { // 1. Create the Push Subscription Model let pushSubscriptionModel = createDefaultPushSubscription(subscriptionId: playerId) - + // 2. Set the internal user let newUser = setNewInternalUser(externalId: nil, pushSubscriptionModel: pushSubscriptionModel) // 3. Make the request OSUserExecutor.fetchIdentityBySubscription(newUser) } - + private func createNewUser(externalId: String?, token: String?) -> OSUserInternal { guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: nil) else { return _mockUser @@ -338,7 +338,7 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager { func isCurrentUser(_ identityModel: OSIdentityModel) -> Bool { return self.identityModelStore.getModel(modelId: identityModel.modelId) != nil } - + /** Clears the existing user's data in preparation for hydration via a fetch user call. */ @@ -463,14 +463,13 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager { func createPushSubscriptionRequest() { // subscriptionExecutor should exist as this should be called after `start()` has been called if let subscriptionExecutor = self.subscriptionExecutor, - let subscriptionModel = pushSubscriptionModel - { + let subscriptionModel = pushSubscriptionModel { subscriptionExecutor.createPushSubscription(subscriptionModel: subscriptionModel, identityModel: user.identityModel) } else { OneSignalLog.onesignalLog(.LL_ERROR, message: "OneSignalUserManagerImpl.createPushSubscriptionRequest cannot be executed due to missing subscriptionExecutor.") } } - + @objc public func getTagsInternal() -> [String: String]? { guard let user = _user else { @@ -541,7 +540,7 @@ extension OneSignalUserManagerImpl { return } start() - + OSUserExecutor.executePendingRequests() OSOperationRepo.sharedInstance.paused = false updateSession(sessionCount: 1, sessionTime: nil, refreshDeviceMetadata: true) @@ -610,26 +609,26 @@ extension OneSignalUserManagerImpl: OSUser { start() return pushSubscriptionImpl } - + public var externalId: String? { guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "externalId") else { return nil } return _user?.identityModel.externalId } - + public var onesignalId: String? { guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "onesignalId") else { return nil } return _user?.identityModel.onesignalId } - + public func addObserver(_ observer: OSUserStateObserver) { // This is a method in the User namespace that doesn't require privacy consent first self.userStateChangesObserver.addObserver(observer) } - + public func removeObserver(_ observer: OSUserStateObserver) { self.userStateChangesObserver.removeObserver(observer) } @@ -780,7 +779,7 @@ extension OneSignalUserManagerImpl { public class OSPushSubscriptionImpl: NSObject, OSPushSubscription { let pushSubscriptionModelStore: OSModelStore - + private var _pushSubscriptionStateChangesObserver: OSObservable? var pushSubscriptionStateChangesObserver: OSObservable { if let observer = _pushSubscriptionStateChangesObserver { @@ -791,16 +790,16 @@ extension OneSignalUserManagerImpl { return pushSubscriptionStateChangesObserver } - + init(pushSubscriptionModelStore: OSModelStore) { self.pushSubscriptionModelStore = pushSubscriptionModelStore } - + public func addObserver(_ observer: OSPushSubscriptionObserver) { // This is a method in the User namespace that doesn't require privacy consent first self.pushSubscriptionStateChangesObserver.addObserver(observer) } - + public func removeObserver(_ observer: OSPushSubscriptionObserver) { self.pushSubscriptionStateChangesObserver.removeObserver(observer) } @@ -825,7 +824,7 @@ extension OneSignalUserManagerImpl { } return pushSubscriptionModelStore.getModel(key: OS_PUSH_SUBSCRIPTION_MODEL_KEY)?.optedIn ?? false } - + /** Enable the push subscription, and prompts if needed. `optedIn` can still be `false` after `optIn()` is called if permission is not granted. */ diff --git a/iOS_SDK/OneSignalSDK/Source/OneSignalSwiftInterface.swift b/iOS_SDK/OneSignalSDK/Source/OneSignalSwiftInterface.swift index 7a048ef4a..b29c525cb 100644 --- a/iOS_SDK/OneSignalSDK/Source/OneSignalSwiftInterface.swift +++ b/iOS_SDK/OneSignalSDK/Source/OneSignalSwiftInterface.swift @@ -56,10 +56,10 @@ public extension OneSignal { static var Location: OSLocation.Type { return __location() } - + static var LiveActivities: OSLiveActivities.Type { return __liveActivities() - } + } } public extension OSDebug { @@ -77,19 +77,19 @@ public extension OSInAppMessages { __paused(newValue) } } - + static func addLifecycleListener(_ listener: OSInAppMessageLifecycleListener) { __add(listener) } - + static func removeLifecycleListener(_ listener: OSInAppMessageLifecycleListener) { __remove(listener) } - + static func addClickListener(_ listener: OSInAppMessageClickListener) { __add(listener) } - + static func removeClickListener(_ listener: OSInAppMessageClickListener) { __remove(listener) } @@ -113,7 +113,7 @@ public extension OSNotifications { static var permissionNative: OSNotificationPermission { return __permissionNative() } - + static func registerForProvisionalAuthorization(_ block: OSUserResponseBlock?) { return __register(forProvisionalAuthorization: block) } @@ -125,11 +125,11 @@ public extension OSNotifications { static func removePermissionObserver(_ observer: OSNotificationPermissionObserver) { return __remove(observer) } - + static func addClickListener(_ listener: OSNotificationClickListener) { return __add(listener) } - + static func removeClickListener(_ listener: OSNotificationClickListener) { return __remove(listener) }