From 02cfc9676c83697b3e3aa3e3f6be66ecc661efec Mon Sep 17 00:00:00 2001 From: Nan Date: Wed, 21 Dec 2022 03:34:39 -0800 Subject: [PATCH 01/17] remove `print` and `NSLog` from SDK, use onesignallog * Replace all Swift `print()` calls with OneSignalLog. * Replace a few NSLogs in the SDK with OneSignalLog as well. --- .../OneSignalCore/Source/API/OSRequests.m | 2 +- .../OneSignalCore/Source/API/OneSignalClient.m | 9 +++++---- .../OneSignalOSCore/Source/OSEventProducer.swift | 7 ++++--- .../OneSignalOSCore/Source/OSModel.swift | 2 -- .../OneSignalOSCore/Source/OSModelStore.swift | 6 +++--- .../Source/OSModelStoreListener.swift | 7 ++++--- .../OneSignalOSCore/Source/OSOperationRepo.swift | 10 ++++++---- .../OneSignalUser/Source/OSIdentityModel.swift | 4 +--- .../Source/OSIdentityOperationExecutor.swift | 15 ++++++++++----- .../Source/OSPropertyOperationExecutor.swift | 9 ++++++--- .../Source/OSSubscriptionModel.swift | 5 ++--- .../Source/OSSubscriptionOperationExecutor.swift | 15 +++++++++------ .../Source/OSUserInternalImpl.swift | 16 +++++++++------- .../Source/OneSignalUserManagerImpl.swift | 7 +++---- .../OneSignalSDK/Source/OSMessagingController.m | 5 +++-- 15 files changed, 66 insertions(+), 53 deletions(-) diff --git a/iOS_SDK/OneSignalSDK/OneSignalCore/Source/API/OSRequests.m b/iOS_SDK/OneSignalSDK/OneSignalCore/Source/API/OSRequests.m index eba9a8b3a..b20122f48 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalCore/Source/API/OSRequests.m +++ b/iOS_SDK/OneSignalSDK/OneSignalCore/Source/API/OSRequests.m @@ -302,7 +302,7 @@ + (instancetype)withUserId:(NSString *)userId externalIdAuthToken:(NSString *)externalIdAuthToken { let request = [OSRequestUpdateLanguage new]; - NSLog(@"Attempting Update to Language"); + [OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"Attempting Update to Language"]; let params = [NSMutableDictionary new]; params[@"app_id"] = appId; diff --git a/iOS_SDK/OneSignalSDK/OneSignalCore/Source/API/OneSignalClient.m b/iOS_SDK/OneSignalSDK/OneSignalCore/Source/API/OneSignalClient.m index ae3580447..16b127cd9 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalCore/Source/API/OneSignalClient.m +++ b/iOS_SDK/OneSignalSDK/OneSignalCore/Source/API/OneSignalClient.m @@ -101,13 +101,14 @@ - (void)executeSimultaneousRequests:(NSDictionary: NSObject { // Not an array as there is at most 1 subsriber per OSEventProducer anyway var subscriber: THandler? public func subscribe(_ handler: THandler) { - print("🔥 OSEventProducer.subscribe() called with handler: \(handler)") + OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OSEventProducer.subscribe() called with handler: \(handler)") // TODO: UM do we want to synchronize on subscribers subscriber = handler // TODO: UM style, implicit or explicit self? } public func unsubscribe(_ handler: THandler) { - print("🔥 OSEventProducer.unsubscribe() called with handler: \(handler)") + OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OSEventProducer.unsubscribe() called with handler: \(handler)") // TODO: UM do we want to synchronize on subscribers subscriber = nil } public func fire(callback: (THandler) -> Void) { - print("🔥 OSEventProducer.fire() called with the following subscribers:") // dump(subscribers) -> uncomment for more verbose log during testing if let subscriber = subscriber { + OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OSEventProducer.fire() called with subscriber") callback(subscriber) } } diff --git a/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSModel.swift b/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSModel.swift index 7a4e4a2e1..96f2249f2 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSModel.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSModel.swift @@ -71,8 +71,6 @@ open class OSModel: NSObject, NSCoding { } open func hydrateModel(_ response: [String: Any]) { - // Log as an error. - print("Error: Function must be overridden.") fatalError("hydrateModel(response:) has not been implemented") } } diff --git a/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSModelStore.swift b/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSModelStore.swift index 2768fd65a..721304e55 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSModelStore.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSModelStore.swift @@ -72,7 +72,7 @@ open class OSModelStore: NSObject { } public func add(id: String, model: TModel) { - print("🔥 OSModelStore add with model \(model)") + OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OSModelStore add() called with model \(model)") // TODO: Check if we are adding the same model? Do we replace? // For example, calling addEmail multiple times with the same email models[id] = model @@ -93,7 +93,7 @@ open class OSModelStore: NSObject { This can happen if remove email or SMS is called and it doesn't exist in the store. */ public func remove(_ id: String) -> Bool { - print("🔥 OSModelStore remove with model \(id)") + OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OSModelStore remove() called with model \(id)") // TODO: Nothing will happen if model doesn't exist in the store if let model = models[id] { models.removeValue(forKey: id) @@ -143,7 +143,7 @@ open class OSModelStore: NSObject { extension OSModelStore: OSModelChangedHandler { public func onModelUpdated(args: OSModelChangedArgs, hydrating: Bool) { - print("🔥 OSModelStore.onChanged() with args \(args)") + OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OSModelStore.onChanged() called with OSModelChangedArgs: \(args)") // persist the changed models to storage OneSignalUserDefaults.initShared().saveCodeableData(forKey: self.storeKey, withValue: self.models) diff --git a/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSModelStoreListener.swift b/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSModelStoreListener.swift index 13cd20b40..b4c217306 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSModelStoreListener.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSModelStoreListener.swift @@ -26,6 +26,7 @@ */ import Foundation +import OneSignalCore public protocol OSModelStoreListener: OSModelStoreChangedHandler { associatedtype TModel: OSModel @@ -51,7 +52,7 @@ extension OSModelStoreListener { } public func onAdded(_ model: OSModel) { - print("🔥 OSModelStoreListener.onAdded() with model \(model)") + OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OSModelStoreListener.onAdded() with model \(model)") guard let addedModel = model as? Self.TModel else { // log error return @@ -62,14 +63,14 @@ extension OSModelStoreListener { } public func onUpdated(_ args: OSModelChangedArgs) { - print("🔥 OSModelStoreListener.onUpdated() with args \(args)") + OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OSModelStoreListener.onUpdated() with args \(args)") if let delta = getUpdateModelDelta(args) { OSOperationRepo.sharedInstance.enqueueDelta(delta) } } public func onRemoved(_ model: OSModel) { - print("🔥 OSModelStoreListener.onRemoved() with model \(model)") + OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OSModelStoreListener.onRemoved() called with model \(model)") guard let removedModel = model as? Self.TModel else { // log error return diff --git a/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSOperationRepo.swift b/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSOperationRepo.swift index ccabe6b4e..84fbf33c1 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSOperationRepo.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSOperationRepo.swift @@ -58,7 +58,7 @@ public class OSOperationRepo: NSObject { } hasCalledStart = true - print("🔥 OSOperationRepo start()") + OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OSOperationRepo calling start()") // register as user observer NotificationCenter.default.addObserver(self, selector: #selector(self.flushDeltaQueue), @@ -76,7 +76,6 @@ public class OSOperationRepo: NSObject { private func pollFlushQueue() { DispatchQueue.global().asyncAfter(deadline: .now() + .seconds(pollIntervalSeconds)) { [weak self] in - print("🔥 OSOperationRepo pollFlushQueue: begin flush") self?.flushDeltaQueue() self?.pollFlushQueue() } @@ -101,7 +100,7 @@ public class OSOperationRepo: NSObject { return } start() - print("🔥 OSOperationRepo enqueueDelta: \(delta)") + OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OSOperationRepo enqueueDelta: \(delta)") deltaQueue.append(delta) // Persist the deltas (including new delta) to storage @@ -113,7 +112,10 @@ public class OSOperationRepo: NSObject { return } start() - print("🔥 OSOperationRepo flushDeltaQueue with queue: \(deltaQueue)") + if (!deltaQueue.isEmpty) { + + OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OSOperationRepo flushDeltaQueue with queue: \(deltaQueue)") + } var index = 0 for delta in deltaQueue { diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSIdentityModel.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSIdentityModel.swift index 226c404b1..b36e389a2 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSIdentityModel.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSIdentityModel.swift @@ -68,7 +68,6 @@ class OSIdentityModel: OSModel { // MARK: - Alias Methods func addAliases(_ aliases: [String: String]) { - print("🔥 OSIdentityModel.addAliases \(aliases).") for (label, id) in aliases { self.aliases[label] = id } @@ -76,7 +75,6 @@ class OSIdentityModel: OSModel { } func removeAliases(_ labels: [String]) { - print("🔥 OSIdentityModel.removeAliases \(labels).") var aliasesToSend: [String: String] = [:] for label in labels { self.aliases.removeValue(forKey: label) @@ -86,7 +84,7 @@ class OSIdentityModel: OSModel { } public override func hydrateModel(_ response: [String: Any]) { - print("🔥 OSIdentityModel hydrateModel()") + OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OSIdentityModel hydrateModel()") for property in response { switch property.key { case "external_id": diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSIdentityOperationExecutor.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSIdentityOperationExecutor.swift index af99cbd9a..f22087c82 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSIdentityOperationExecutor.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSIdentityOperationExecutor.swift @@ -50,7 +50,7 @@ class OSIdentityOperationExecutor: OSOperationExecutor { } func enqueueDelta(_ delta: OSDelta) { - print("🔥 OSIdentityOperationExecutor enqueueDelta: \(delta)") + OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OSIdentityOperationExecutor enqueueDelta: \(delta)") deltaQueue.append(delta) } @@ -59,6 +59,9 @@ class OSIdentityOperationExecutor: OSOperationExecutor { } func processDeltaQueue() { + if (!deltaQueue.isEmpty) { + OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OSIdentityOperationExecutor processDeltaQueue with queue: \(deltaQueue)") + } for delta in deltaQueue { guard let model = delta.model as? OSIdentityModel, let aliases = delta.value as? [String: String] @@ -81,7 +84,7 @@ class OSIdentityOperationExecutor: OSOperationExecutor { default: // Log error - print("🔥 OSIdentityOperationExecutor met incompatible OSDelta type.") + OneSignalLog.onesignalLog(.LL_DEBUG, message: "OSIdentityOperationExecutor met incompatible OSDelta type: \(delta)") } } @@ -96,7 +99,7 @@ class OSIdentityOperationExecutor: OSOperationExecutor { } func enqueueRequest(_ request: OneSignalRequest) { - print("🔥 OSIdentityOperationExecutor enqueueRequest: \(request)") + OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OSIdentityOperationExecutor enqueueRequest: \(request)") requestQueue.append(request) } @@ -117,7 +120,8 @@ class OSIdentityOperationExecutor: OSOperationExecutor { } func executeAddAliasesRequest(_ request: OSRequestAddAliases) { - print("🔥 OSIdentityOperationExecutor: executeAddAliasesRequest making request: \(request)") + OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OSIdentityOperationExecutor: executeAddAliasesRequest making request: \(request)") + OneSignalClient.shared().execute(request) { result in // Mock a response let response = ["onesignalId": UUID().uuidString, "label01": "id01"] @@ -138,7 +142,8 @@ class OSIdentityOperationExecutor: OSOperationExecutor { } func executeRemoveAliasRequest(_ request: OSRequestRemoveAlias) { - print("🔥 OSIdentityOperationExecutor: executeRemoveAliasRequest making request: \(request)") + OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OSIdentityOperationExecutor: executeRemoveAliasRequest making request: \(request)") + OneSignalClient.shared().execute(request) { result in // Mock a response diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSPropertyOperationExecutor.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSPropertyOperationExecutor.swift index 2e1b471e3..e292dd059 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSPropertyOperationExecutor.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSPropertyOperationExecutor.swift @@ -50,7 +50,7 @@ class OSPropertyOperationExecutor: OSOperationExecutor { } func enqueueDelta(_ delta: OSDelta) { - print("🔥 OSPropertyOperationExecutor enqueue delta\(delta)") + OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OSPropertyOperationExecutor enqueue delta\(delta)") deltaQueue.append(delta) } @@ -59,6 +59,9 @@ class OSPropertyOperationExecutor: OSOperationExecutor { } func processDeltaQueue() { + if (!deltaQueue.isEmpty) { + OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OSPropertyOperationExecutor processDeltaQueue with queue: \(deltaQueue)") + } for delta in deltaQueue { guard let model = delta.model as? OSPropertiesModel else { // Log error @@ -84,7 +87,7 @@ class OSPropertyOperationExecutor: OSOperationExecutor { } func enqueueRequest(_ request: OneSignalRequest) { - print("🔥 OSPropertyOperationExecutor enqueueRequest: \(request)") + OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OSPropertyOperationExecutor enqueueRequest: \(request)") requestQueue.append(request) } @@ -104,7 +107,7 @@ class OSPropertyOperationExecutor: OSOperationExecutor { guard request.prepareForExecution() else { return } - print("🔥 OSPropertyOperationExecutor: executeUpdatePropertiesRequest making request: \(request)") + OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OSPropertyOperationExecutor: executeUpdatePropertiesRequest making request: \(request)") OneSignalClient.shared().execute(request) { result in // On success, remove request from cache, and hydrate model diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSSubscriptionModel.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSSubscriptionModel.swift index af5d478c8..639ea01b1 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSSubscriptionModel.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSSubscriptionModel.swift @@ -221,7 +221,7 @@ class OSSubscriptionModel: OSModel { } public override func hydrateModel(_ response: [String: Any]) { - print("🔥 OSSubscriptionModel hydrateModel()") + OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OSSubscriptionModel hydrateModel()") for property in response { switch property.key { case "id": @@ -323,8 +323,7 @@ extension OSSubscriptionModel { let stateChanges = OSPushSubscriptionStateChanges(to: newSubscriptionState, from: prevSubscriptionState) // TODO: Don't fire observer until server is udated - print("🔥 firePushSubscriptionChanged from \(prevSubscriptionState.toDictionary()) to \(newSubscriptionState.toDictionary())") - + OneSignalLog.onesignalLog(.LL_VERBOSE, message: "firePushSubscriptionChanged from \(prevSubscriptionState.toDictionary()) to \(newSubscriptionState.toDictionary())") OneSignalUserManagerImpl.sharedInstance.pushSubscriptionStateChangesObserver.notifyChange(stateChanges) } } diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSSubscriptionOperationExecutor.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSSubscriptionOperationExecutor.swift index a24a31e38..7816f3885 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSSubscriptionOperationExecutor.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSSubscriptionOperationExecutor.swift @@ -50,7 +50,7 @@ class OSSubscriptionOperationExecutor: OSOperationExecutor { } func enqueueDelta(_ delta: OSDelta) { - print("🔥 OSSubscriptionOperationExecutor enqueueDelta: \(delta)") + OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OSSubscriptionOperationExecutor enqueueDelta: \(delta)") deltaQueue.append(delta) } @@ -59,6 +59,9 @@ class OSSubscriptionOperationExecutor: OSOperationExecutor { } func processDeltaQueue() { + if (!deltaQueue.isEmpty) { + OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OSSubscriptionOperationExecutor processDeltaQueue with queue: \(deltaQueue)") + } for delta in deltaQueue { guard let model = delta.model as? OSSubscriptionModel else { // Log error @@ -88,7 +91,7 @@ class OSSubscriptionOperationExecutor: OSOperationExecutor { default: // Log error - print("🔥 OSSubscriptionOperationExecutor met incompatible OSDelta type.") + OneSignalLog.onesignalLog(.LL_DEBUG, message: "OSSubscriptionOperationExecutor met incompatible OSDelta type: \(delta).") } } @@ -103,7 +106,7 @@ class OSSubscriptionOperationExecutor: OSOperationExecutor { } func enqueueRequest(_ request: OneSignalRequest) { - print("🔥 OSSubscriptionOperationExecutor enqueueRequest: \(request)") + OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OSSubscriptionOperationExecutor enqueueRequest: \(request)") requestQueue.append(request) } @@ -129,7 +132,7 @@ class OSSubscriptionOperationExecutor: OSOperationExecutor { guard request.prepareForExecution() else { return } - print("🔥 OSSubscriptionOperationExecutor: executeCreateSubscriptionRequest making request: \(request)") + OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OSSubscriptionOperationExecutor: executeCreateSubscriptionRequest making request: \(request)") OneSignalClient.shared().execute(request) { result in guard let response = result?["subscription"] as? [String : Any] else { OneSignalLog.onesignalLog(.LL_ERROR, message: "Unabled to parse response to create subscription request") @@ -153,7 +156,7 @@ class OSSubscriptionOperationExecutor: OSOperationExecutor { } // This request can be executed as-is. - print("🔥 OSSubscriptionOperationExecutor: executeDeleteSubscriptionRequest making request: \(request)") + OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OSSubscriptionOperationExecutor: executeDeleteSubscriptionRequest making request: \(request)") OneSignalClient.shared().execute(request) { result in // On success, remove request from cache. No model hydration occurs. @@ -168,7 +171,7 @@ class OSSubscriptionOperationExecutor: OSOperationExecutor { } func executeUpdateSubscriptionRequest(_ request: OSRequestUpdateSubscription) { - print("🔥 OSSubscriptionOperationExecutor: executeUpdateSubscriptionRequest making request: \(request)") + OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OSSubscriptionOperationExecutor: executeUpdateSubscriptionRequest making request: \(request)") guard request.prepareForExecution() else { return diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSUserInternalImpl.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSUserInternalImpl.swift index a41427923..7aac16f26 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSUserInternalImpl.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSUserInternalImpl.swift @@ -79,13 +79,13 @@ class OSUserInternalImpl: NSObject, OSUserInternal { */ func addAliases(_ aliases: [String: String]) { // Decide if the non-offending aliases should still be added. - print("🔥 OSUserInternalImpl addAliases() called") + OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OneSignal.User addAliases called with: \(aliases)") guard aliases[OS_ONESIGNAL_ID] == nil, aliases[OS_EXTERNAL_ID] == nil, !aliases.values.contains("") else { // log error - print("🔥 OSUserInternal addAliases: Cannot use \(OS_ONESIGNAL_ID) or \(OS_EXTERNAL_ID) as a alias label. Or, cannot use empty string as an alias ID.") + OneSignalLog.onesignalLog(.LL_ERROR, message: "OneSignal.User addAliases error: Cannot use \(OS_ONESIGNAL_ID) or \(OS_EXTERNAL_ID) as a alias label. Or, cannot use empty string as an alias ID.") return } identityModel.addAliases(aliases) @@ -95,12 +95,12 @@ class OSUserInternalImpl: NSObject, OSUserInternal { Prohibit the removal of `onesignal_id` and `external_id`. */ func removeAliases(_ labels: [String]) { - print("🔥 OSUserInternalImpl removeAliases() called") + OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OneSignal.User removeAliases called with: \(labels)") guard !labels.contains(OS_ONESIGNAL_ID), !labels.contains(OS_EXTERNAL_ID) else { // log error - print("🔥 OSUserInternal removeAliases: Cannot use \(OS_ONESIGNAL_ID) or \(OS_EXTERNAL_ID) as a alias label.") + OneSignalLog.onesignalLog(.LL_ERROR, message: "OneSignal.User removeAliases error: Cannot use \(OS_ONESIGNAL_ID) or \(OS_EXTERNAL_ID) as a alias label.") return } identityModel.removeAliases(labels) @@ -109,19 +109,21 @@ class OSUserInternalImpl: NSObject, OSUserInternal { // MARK: - Tags func addTags(_ tags: [String: String]) { - print("🔥 OSUserInternalImpl addTags() called") + OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OneSignal.User addTags called with: \(tags)") propertiesModel.addTags(tags) } func removeTags(_ tags: [String]) { - print("🔥 OSUserInternalImpl removeTags() called") + OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OneSignal.User removeTags called with: \(tags)") + propertiesModel.removeTags(tags) } // MARK: - Location func setLocation(lat: Float, long: Float) { - print("🔥 OSUserInternalImpl setLocation() called") + OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OneSignal.User setLocation called with lat: \(lat) long: \(long)") + propertiesModel.lat = lat propertiesModel.long = long } diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift index 3443ace61..bfd7a5e2d 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift @@ -172,7 +172,7 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager { } hasCalledStart = true - print("🔥 OneSignalUserManagerImpl start()") + OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OneSignalUserManager calling start") OSNotificationsManager.delegate = self @@ -210,7 +210,7 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager { // Log error return } - print("🔥 OneSignalUserManagerImpl login(\(externalId)) called") + OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OneSignal.User login called with externalId: \(externalId)") _ = _login(externalId: externalId, token: token) } @@ -267,8 +267,7 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager { guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: nil) else { return _mockUser } - - print("🔥 OneSignalUserManagerImpl private _login(\(externalId ?? "nil")) called") + OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OneSignalUserManager internal _login called with externalId: \(externalId ?? "nil")") // If have token, validate token. Account for this being a requirement. // Logging into an identified user from an anonymous user diff --git a/iOS_SDK/OneSignalSDK/Source/OSMessagingController.m b/iOS_SDK/OneSignalSDK/Source/OSMessagingController.m index e246f376a..dd8626782 100644 --- a/iOS_SDK/OneSignalSDK/Source/OSMessagingController.m +++ b/iOS_SDK/OneSignalSDK/Source/OSMessagingController.m @@ -525,10 +525,11 @@ - (void)setDataForRedisplay:(OSInAppMessageInternal *)message { BOOL messageDismissed = [_seenInAppMessages containsObject:message.messageId]; let redisplayMessageSavedData = [_redisplayedInAppMessages objectForKey:message.messageId]; - NSLog(@"Redisplay dismissed: %@ and data: %@", messageDismissed ? @"YES" : @"NO", redisplayMessageSavedData.jsonRepresentation.description); + [OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"Redisplay dismissed: %@ and data: %@", messageDismissed ? @"YES" : @"NO", redisplayMessageSavedData.jsonRepresentation.description]]; if (messageDismissed && redisplayMessageSavedData) { - NSLog(@"Redisplay IAM: %@", message.jsonRepresentation.description); + [OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"Redisplay IAM: %@", message.jsonRepresentation.description]]; + message.displayStats.displayQuantity = redisplayMessageSavedData.displayStats.displayQuantity; message.displayStats.lastDisplayTime = redisplayMessageSavedData.displayStats.lastDisplayTime; From 4bfb038c7c80dc89d7218e0ce97ad8554ebbe6a6 Mon Sep 17 00:00:00 2001 From: Nan Date: Wed, 28 Dec 2022 13:31:51 -0800 Subject: [PATCH 02/17] refine API for Swift Refine some more APIs for Swift --- .../OSNotificationsManager.h | 10 +-- .../OneSignalOutcomes/OneSignalOutcomes.h | 3 +- .../OneSignalSDK/Source/OneSignalFramework.h | 12 ++-- .../OneSignalSDK/Source/OneSignalLocation.h | 4 +- .../Source/OneSignalSwiftInterface.swift | 68 +++++++++++++++++++ .../UnitTests/UserModelSwiftTests.swift | 11 --- 6 files changed, 82 insertions(+), 26 deletions(-) diff --git a/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.h b/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.h index e18285d17..4922e38bb 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.h +++ b/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.h @@ -39,15 +39,15 @@ typedef void (^OSNotificationOpenedBlock)(OSNotificationOpenedResult * _Nonnull Public API. */ @protocol OSNotifications -+ (BOOL)permission; -+ (BOOL)canRequestPermission; ++ (BOOL)permission NS_REFINED_FOR_SWIFT; ++ (BOOL)canRequestPermission NS_REFINED_FOR_SWIFT; + (void)setNotificationWillShowInForegroundHandler:(OSNotificationWillShowInForegroundBlock _Nullable)block; + (void)setNotificationOpenedHandler:(OSNotificationOpenedBlock _Nullable)block; + (void)requestPermission:(OSUserResponseBlock _Nullable )block; + (void)requestPermission:(OSUserResponseBlock _Nullable )block fallbackToSettings:(BOOL)fallback; -+ (void)registerForProvisionalAuthorization:(OSUserResponseBlock _Nullable )block; -+ (void)addPermissionObserver:(NSObject*_Nonnull)observer; -+ (void)removePermissionObserver:(NSObject*_Nonnull)observer; ++ (void)registerForProvisionalAuthorization:(OSUserResponseBlock _Nullable )block NS_REFINED_FOR_SWIFT; ++ (void)addPermissionObserver:(NSObject*_Nonnull)observer NS_REFINED_FOR_SWIFT; ++ (void)removePermissionObserver:(NSObject*_Nonnull)observer NS_REFINED_FOR_SWIFT; + (void)clearAll; @end diff --git a/iOS_SDK/OneSignalSDK/OneSignalOutcomes/OneSignalOutcomes.h b/iOS_SDK/OneSignalSDK/OneSignalOutcomes/OneSignalOutcomes.h index 4d6dffad6..e3dcb57d1 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalOutcomes/OneSignalOutcomes.h +++ b/iOS_SDK/OneSignalSDK/OneSignalOutcomes/OneSignalOutcomes.h @@ -48,7 +48,8 @@ @protocol OSSession + (void)addOutcome:(NSString * _Nonnull)name; + (void)addUniqueOutcome:(NSString * _Nonnull)name; -+ (void)addOutcomeWithValue:(NSString * _Nonnull)name value:(NSNumber * _Nonnull)value; ++ (void)addOutcomeWithValue:(NSString * _Nonnull)name value:(NSNumber * _Nonnull)value NS_REFINED_FOR_SWIFT; + @end @interface OSOutcomes : NSObject diff --git a/iOS_SDK/OneSignalSDK/Source/OneSignalFramework.h b/iOS_SDK/OneSignalSDK/Source/OneSignalFramework.h index aa77f9748..0a3c8fe0b 100755 --- a/iOS_SDK/OneSignalSDK/Source/OneSignalFramework.h +++ b/iOS_SDK/OneSignalSDK/Source/OneSignalFramework.h @@ -90,16 +90,14 @@ NS_SWIFT_NAME(login(externalId:token:)); + (Class)Debug NS_REFINED_FOR_SWIFT; #pragma mark Privacy Consent -+ (void)setPrivacyConsent:(BOOL)granted; -+ (BOOL)getPrivacyConsent; ++ (void)setPrivacyConsent:(BOOL)granted NS_REFINED_FOR_SWIFT; ++ (BOOL)getPrivacyConsent NS_REFINED_FOR_SWIFT; /** * Tells your application if privacy consent is still needed from the current device. * Consent should be provided prior to the invocation of `initialize` to ensure compliance. */ -+ (BOOL)requiresPrivacyConsent; -+ (void)setRequiresPrivacyConsent:(BOOL)required; - -#pragma mark Permission, Subscription, and Email Observers ++ (BOOL)requiresPrivacyConsent NS_REFINED_FOR_SWIFT; ++ (void)setRequiresPrivacyConsent:(BOOL)required NS_REFINED_FOR_SWIFT; #pragma mark In-App Messaging + (Class)InAppMessages NS_REFINED_FOR_SWIFT; @@ -107,7 +105,7 @@ NS_SWIFT_NAME(login(externalId:token:)); #pragma mark Location + (Class)Location NS_REFINED_FOR_SWIFT; -#pragma mark Outcomes +#pragma mark Session + (Class)Session NS_REFINED_FOR_SWIFT; #pragma mark Extension diff --git a/iOS_SDK/OneSignalSDK/Source/OneSignalLocation.h b/iOS_SDK/OneSignalSDK/Source/OneSignalLocation.h index 1ac7a0f1a..54d7bdebe 100644 --- a/iOS_SDK/OneSignalSDK/Source/OneSignalLocation.h +++ b/iOS_SDK/OneSignalSDK/Source/OneSignalLocation.h @@ -45,8 +45,8 @@ typedef struct os_last_location { @protocol OSLocation // - Request and track user's location + (void)requestPermission; -+ (void)setShared:(BOOL)enable; -+ (BOOL)isShared; ++ (void)setShared:(BOOL)enable NS_REFINED_FOR_SWIFT; ++ (BOOL)isShared NS_REFINED_FOR_SWIFT; @end @interface OneSignalLocation : NSObject diff --git a/iOS_SDK/OneSignalSDK/Source/OneSignalSwiftInterface.swift b/iOS_SDK/OneSignalSDK/Source/OneSignalSwiftInterface.swift index aef62bc31..7bf6810ba 100644 --- a/iOS_SDK/OneSignalSDK/Source/OneSignalSwiftInterface.swift +++ b/iOS_SDK/OneSignalSDK/Source/OneSignalSwiftInterface.swift @@ -55,4 +55,72 @@ public extension OneSignal { static var Location: OSLocation.Type { return __location() } + + static var requiresPrivacyConsent: Bool { + get { + return __requiresPrivacyConsent() + } + set { + __setRequiresPrivacyConsent(newValue) + } + } + + static var privacyConsent: Bool { + get { + return __getPrivacyConsent() + } + set { + __setPrivacyConsent(newValue) + } + } +} + +public extension OSInAppMessages { + static var Paused: Bool { + get { + return __paused() + } + set { + __paused(newValue) + } + } +} + +public extension OSSession { + static func addOutcome(_ name: String, _ value: NSNumber) { + __addOutcome(withValue: name, value: value) + } +} + +public extension OSNotifications { + static var permission: Bool { + return __permission() + } + + static var canRequestPermission: Bool { + return __canRequestPermission() + } + + static func registerForProvisionalAuthorization(_ block: OSUserResponseBlock?) { + return __register(forProvisionalAuthorization: block) + } + + static func addPermissionObserver(_ observer: OSPermissionObserver) { + return __add(observer) + } + + static func removePermissionObserver(_ observer: OSPermissionObserver) { + return __remove(observer) + } +} + +public extension OSLocation { + static var isShared: Bool { + get { + return __isShared() + } + set { + __setShared(newValue) + } + } } diff --git a/iOS_SDK/OneSignalSDK/UnitTests/UserModelSwiftTests.swift b/iOS_SDK/OneSignalSDK/UnitTests/UserModelSwiftTests.swift index 59051ad75..cadd2576b 100644 --- a/iOS_SDK/OneSignalSDK/UnitTests/UserModelSwiftTests.swift +++ b/iOS_SDK/OneSignalSDK/UnitTests/UserModelSwiftTests.swift @@ -28,17 +28,6 @@ import XCTest import OneSignalFramework -extension OSInAppMessages { - static var Paused: Bool { - get { - return __paused() - } - set { - __paused(newValue) - } - } -} - // Non-class type 'OSPushSubscriptionTestObserver' cannot conform to class protocol 'OSPushSubscriptionObserver' // ^ Cannot use a struct for an OSPushSubscriptionObserver From e1bf7718700fe26d520ca9ccbe933c0c90d2bd17 Mon Sep 17 00:00:00 2001 From: Nan Date: Wed, 28 Dec 2022 13:42:41 -0800 Subject: [PATCH 03/17] update Common Defines variables * For clarity, rename `OSUD_PLAYER_ID_TO` to `OSUD_PUSH_SUBSCRIPTION_ID` * And `OSUD_PUSH_TOKEN_TO` to `OSUD_PUSH_TOKEN` * Remove from Common Defines values no longer used --- .../Source/OneSignalCommonDefines.h | 26 +++---------------- ...ignalNotificationServiceExtensionHandler.m | 2 +- .../OneSignalReceiveReceiptsController.m | 2 +- .../OSNotificationsManager.m | 6 ++--- .../Source/OSSubscriptionModel.swift | 2 +- .../Source/OneSignalUserManagerImpl.swift | 4 +-- iOS_SDK/OneSignalSDK/Source/OneSignal.m | 4 +-- iOS_SDK/OneSignalSDK/UnitTests/UnitTests.m | 4 +-- 8 files changed, 15 insertions(+), 35 deletions(-) diff --git a/iOS_SDK/OneSignalSDK/OneSignalCore/Source/OneSignalCommonDefines.h b/iOS_SDK/OneSignalSDK/OneSignalCore/Source/OneSignalCommonDefines.h index bcf269bf2..754c0ca52 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalCore/Source/OneSignalCommonDefines.h +++ b/iOS_SDK/OneSignalSDK/OneSignalCore/Source/OneSignalCommonDefines.h @@ -65,27 +65,9 @@ #define OSUD_PERMISSION_EPHEMERAL_FROM @"OSUD_PERMISSION_EPHEMERAL_FROM" // * OSUD_PERMISSION_EPHEMERAL_FROM #define OSUD_LANGUAGE @"OSUD_LANGUAGE" // * OSUD_LANGUAGE #define DEFAULT_LANGUAGE @"en" // * OSUD_LANGUAGE -// Player -#define OSUD_EXTERNAL_USER_ID @"OS_EXTERNAL_USER_ID" // * OSUD_EXTERNAL_USER_ID -#define OSUD_PLAYER_ID_TO @"GT_PLAYER_ID" // * OSUD_PLAYER_ID_TO -#define OSUD_PLAYER_ID_FROM @"GT_PLAYER_ID_LAST" // * OSUD_PLAYER_ID_FROM -#define OSUD_PUSH_TOKEN_TO @"GT_DEVICE_TOKEN" // * OSUD_PUSH_TOKEN_TO -#define OSUD_PUSH_TOKEN_FROM @"GT_DEVICE_TOKEN_LAST" // * OSUD_PUSH_TOKEN_FROM -#define OSUD_USER_SUBSCRIPTION_TO @"ONESIGNAL_SUBSCRIPTION" // * OSUD_USER_SUBSCRIPTION_TO -#define OSUD_USER_SUBSCRIPTION_FROM @"ONESIGNAL_SUBSCRIPTION_SETTING" // * OSUD_USER_SUBSCRIPTION_FROM -#define OSUD_EXTERNAL_ID_AUTH_CODE @"OSUD_EXTERNAL_ID_AUTH_CODE" -// Email -#define OSUD_EMAIL_ADDRESS @"EMAIL_ADDRESS" // * OSUD_EMAIL_ADDRESS -#define OSUD_EMAIL_PLAYER_ID @"GT_EMAIL_PLAYER_ID" // * OSUD_EMAIL_PLAYER_ID -#define OSUD_EMAIL_EXTERNAL_USER_ID @"OSUD_EMAIL_EXTERNAL_USER_ID" // OSUD_EMAIL_EXTERNAL_USER_ID -#define OSUD_REQUIRE_EMAIL_AUTH @"GT_REQUIRE_EMAIL_AUTH" // * OSUD_REQUIRE_EMAIL_AUTH -#define OSUD_EMAIL_AUTH_CODE @"GT_EMAIL_AUTH_CODE" // * OSUD_EMAIL_AUTH_CODE -// SMS -#define OSUD_SMS_NUMBER @"OSUD_SMS_NUMBER" -#define OSUD_SMS_PLAYER_ID @"OSUD_SMS_PLAYER_ID" -#define OSUD_SMS_EXTERNAL_USER_ID @"OSUD_SMS_EXTERNAL_USER_ID" -#define OSUD_REQUIRE_SMS_AUTH @"OSUD_REQUIRE_SMS_AUTH" -#define OSUD_SMS_AUTH_CODE @"OSUD_SMS_AUTH_CODE" +// Push Subscription +#define OSUD_PUSH_SUBSCRIPTION_ID @"GT_PLAYER_ID" // * OSUD_PUSH_SUBSCRIPTION_ID +#define OSUD_PUSH_TOKEN @"GT_DEVICE_TOKEN" // * OSUD_PUSH_TOKEN // Notification #define OSUD_LAST_MESSAGE_OPENED @"GT_LAST_MESSAGE_OPENED_" // * OSUD_MOST_RECENT_NOTIFICATION_OPENED #define OSUD_NOTIFICATION_OPEN_LAUNCH_URL @"ONESIGNAL_INAPP_LAUNCH_URL" // * OSUD_NOTIFICATION_OPEN_LAUNCH_URL @@ -118,8 +100,6 @@ #define OSUD_APP_LAST_CLOSED_TIME @"GT_LAST_CLOSED_TIME" // * OSUD_APP_LAST_CLOSED_TIME #define OSUD_UNSENT_ACTIVE_TIME @"GT_UNSENT_ACTIVE_TIME" // * OSUD_UNSENT_ACTIVE_TIME #define OSUD_UNSENT_ACTIVE_TIME_ATTRIBUTED @"GT_UNSENT_ACTIVE_TIME_ATTRIBUTED" // * OSUD_UNSENT_ACTIVE_TIME_ATTRIBUTED -#define OSUD_PLAYER_TAGS @"OSUD_PLAYER_TAGS" - // * OSUD_PLAYER_TAGS // Deprecated Selectors #define DEPRECATED_SELECTORS @[ @"application:didReceiveLocalNotification:", \ diff --git a/iOS_SDK/OneSignalSDK/OneSignalExtension/OneSignalNotificationServiceExtensionHandler.m b/iOS_SDK/OneSignalSDK/OneSignalExtension/OneSignalNotificationServiceExtensionHandler.m index 957eff28c..70415ab18 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalExtension/OneSignalNotificationServiceExtensionHandler.m +++ b/iOS_SDK/OneSignalSDK/OneSignalExtension/OneSignalNotificationServiceExtensionHandler.m @@ -139,7 +139,7 @@ + (void)onNotificationReceived:(NSString *)receivedNotificationId withBlockingTa // Track confirmed delivery let sharedUserDefaults = OneSignalUserDefaults.initShared; - let playerId = [sharedUserDefaults getSavedStringForKey:OSUD_PLAYER_ID_TO defaultValue:nil]; + let playerId = [sharedUserDefaults getSavedStringForKey:OSUD_PUSH_SUBSCRIPTION_ID defaultValue:nil]; let appId = [sharedUserDefaults getSavedStringForKey:OSUD_APP_ID defaultValue:nil]; // Randomize send of confirmed deliveries to lessen traffic for high recipient notifications int randomDelay = semaphore != nil ? arc4random_uniform(MAX_CONF_DELIVERY_DELAY) : 0; diff --git a/iOS_SDK/OneSignalSDK/OneSignalExtension/OneSignalReceiveReceiptsController.m b/iOS_SDK/OneSignalSDK/OneSignalExtension/OneSignalReceiveReceiptsController.m index b0bc90158..f3ab87765 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalExtension/OneSignalReceiveReceiptsController.m +++ b/iOS_SDK/OneSignalSDK/OneSignalExtension/OneSignalReceiveReceiptsController.m @@ -38,7 +38,7 @@ - (BOOL)isReceiveReceiptsEnabled { - (void)sendReceiveReceiptWithNotificationId:(NSString *)notificationId { let sharedUserDefaults = OneSignalUserDefaults.initShared; - let playerId = [sharedUserDefaults getSavedStringForKey:OSUD_PLAYER_ID_TO defaultValue:nil]; + let playerId = [sharedUserDefaults getSavedStringForKey:OSUD_PUSH_SUBSCRIPTION_ID defaultValue:nil]; let appId = [sharedUserDefaults getSavedStringForKey:OSUD_APP_ID defaultValue:nil]; [self sendReceiveReceiptWithPlayerId:playerId diff --git a/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.m b/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.m index 8798afd18..58b2f74e2 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.m +++ b/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.m @@ -182,7 +182,7 @@ + (OSPermissionStateInternal*)lastPermissionState { static NSString *_pushToken; + (NSString*)pushToken { if (!_pushToken) { - _pushToken = [OneSignalUserDefaults.initShared getSavedStringForKey:OSUD_PUSH_TOKEN_TO defaultValue:nil]; + _pushToken = [OneSignalUserDefaults.initShared getSavedStringForKey:OSUD_PUSH_TOKEN defaultValue:nil]; } return _pushToken; } @@ -190,7 +190,7 @@ + (NSString*)pushToken { static NSString *_pushSubscriptionId; + (NSString*)pushSubscriptionId { if (!_pushSubscriptionId) { - _pushSubscriptionId = [OneSignalUserDefaults.initShared getSavedStringForKey:OSUD_PLAYER_ID_TO defaultValue:nil]; + _pushSubscriptionId = [OneSignalUserDefaults.initShared getSavedStringForKey:OSUD_PUSH_SUBSCRIPTION_ID defaultValue:nil]; } return _pushSubscriptionId; } @@ -393,7 +393,7 @@ + (void)didRegisterForRemoteNotifications:(UIApplication *)app _pushToken = parsedDeviceToken; // Cache push token - [OneSignalUserDefaults.initShared saveStringForKey:OSUD_PUSH_TOKEN_TO withValue:_pushToken]; + [OneSignalUserDefaults.initShared saveStringForKey:OSUD_PUSH_TOKEN withValue:_pushToken]; [self sendPushTokenToDelegate]; } diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSSubscriptionModel.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSSubscriptionModel.swift index 639ea01b1..156f574f0 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSSubscriptionModel.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSSubscriptionModel.swift @@ -118,7 +118,7 @@ class OSSubscriptionModel: OSModel { } // Cache the subscriptionId as it persists across users on the device?? - OneSignalUserDefaults.initShared().saveString(forKey: OSUD_PLAYER_ID_TO, withValue: subscriptionId) + OneSignalUserDefaults.initShared().saveString(forKey: OSUD_PUSH_SUBSCRIPTION_ID, withValue: subscriptionId) firePushSubscriptionChanged(.subscriptionId(oldValue)) } diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift index bfd7a5e2d..4aca05652 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift @@ -349,8 +349,8 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager { func createDefaultPushSubscription() -> OSSubscriptionModel { let sharedUserDefaults = OneSignalUserDefaults.initShared() let accepted = OSNotificationsManager.currentPermissionState.accepted - let token = sharedUserDefaults.getSavedString(forKey: OSUD_PUSH_TOKEN_TO, defaultValue: nil) - let subscriptionId = sharedUserDefaults.getSavedString(forKey: OSUD_PLAYER_ID_TO, defaultValue: nil) + let token = sharedUserDefaults.getSavedString(forKey: OSUD_PUSH_TOKEN, defaultValue: nil) + let subscriptionId = sharedUserDefaults.getSavedString(forKey: OSUD_PUSH_SUBSCRIPTION_ID, defaultValue: nil) return OSSubscriptionModel(type: .push, address: token, diff --git a/iOS_SDK/OneSignalSDK/Source/OneSignal.m b/iOS_SDK/OneSignalSDK/Source/OneSignal.m index d94bd3b03..341ab7b66 100755 --- a/iOS_SDK/OneSignalSDK/Source/OneSignal.m +++ b/iOS_SDK/OneSignalSDK/Source/OneSignal.m @@ -578,8 +578,8 @@ + (void)handleAppIdChange:(NSString*)appId { [standardUserDefaults saveStringForKey:OSUD_APP_ID withValue:appId]; // Remove player_id from both standard and shared NSUserDefaults - [standardUserDefaults removeValueForKey:OSUD_PLAYER_ID_TO]; - [sharedUserDefaults removeValueForKey:OSUD_PLAYER_ID_TO]; + [standardUserDefaults removeValueForKey:OSUD_PUSH_SUBSCRIPTION_ID]; + [sharedUserDefaults removeValueForKey:OSUD_PUSH_SUBSCRIPTION_ID]; // Clear all cached data, does not start User Module nor call logout. [OneSignalUserManagerImpl.sharedInstance clearAllModelsFromStores]; diff --git a/iOS_SDK/OneSignalSDK/UnitTests/UnitTests.m b/iOS_SDK/OneSignalSDK/UnitTests/UnitTests.m index ab00a7e56..45f6e4d7b 100644 --- a/iOS_SDK/OneSignalSDK/UnitTests/UnitTests.m +++ b/iOS_SDK/OneSignalSDK/UnitTests/UnitTests.m @@ -1852,7 +1852,7 @@ - (void)testAddingSharedKeysIfMissing { // 2. Remove shared keys to simulate the state of coming from a pre-2.12.1 version [OneSignalUserDefaults.initShared removeValueForKey:OSUD_APP_ID]; - [OneSignalUserDefaults.initShared removeValueForKey:OSUD_PLAYER_ID_TO]; + [OneSignalUserDefaults.initShared removeValueForKey:OSUD_PUSH_SUBSCRIPTION_ID]; // 3. Restart app [UnitTestCommonMethods backgroundApp]; @@ -1861,7 +1861,7 @@ - (void)testAddingSharedKeysIfMissing { // 4. Ensure values are present again XCTAssertNotNil([OneSignalUserDefaults.initShared getSavedSetForKey:OSUD_APP_ID defaultValue:nil]); - XCTAssertNotNil([OneSignalUserDefaults.initShared getSavedSetForKey:OSUD_PLAYER_ID_TO defaultValue:nil]); + XCTAssertNotNil([OneSignalUserDefaults.initShared getSavedSetForKey:OSUD_PUSH_SUBSCRIPTION_ID defaultValue:nil]); } // iOS 10 - Notification Service Extension test - local file From e396cee9b17fcae69da5d71a0a9cfe75248a877d Mon Sep 17 00:00:00 2001 From: Nan Date: Wed, 28 Dec 2022 13:49:24 -0800 Subject: [PATCH 04/17] Remove no longer used Requests --- .../OneSignalCore/Source/API/OSRequests.h | 64 ----- .../OneSignalCore/Source/API/OSRequests.m | 263 ------------------ 2 files changed, 327 deletions(-) diff --git a/iOS_SDK/OneSignalSDK/OneSignalCore/Source/API/OSRequests.h b/iOS_SDK/OneSignalSDK/OneSignalCore/Source/API/OSRequests.h index 30ab63835..bc3a2c3d3 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalCore/Source/API/OSRequests.h +++ b/iOS_SDK/OneSignalSDK/OneSignalCore/Source/API/OSRequests.h @@ -33,10 +33,6 @@ NS_ASSUME_NONNULL_BEGIN -@interface OSRequestGetTags : OneSignalRequest -+ (instancetype)withUserId:(NSString *)userId appId:(NSString *)appId; -@end - @interface OSRequestGetIosParams : OneSignalRequest + (instancetype)withUserId:(NSString *)userId appId:(NSString *)appId; @end @@ -45,72 +41,12 @@ NS_ASSUME_NONNULL_BEGIN + (instancetype)withAppId:(NSString *)appId withJson:(NSMutableDictionary *)json; @end -@interface OSRequestUpdateNotificationTypes : OneSignalRequest -+ (instancetype)withUserId:(NSString *)userId appId:(NSString *)appId notificationTypes:(NSNumber *)notificationTypes; -@end - -@interface OSRequestSendPurchases : OneSignalRequest -+ (instancetype)withUserId:(NSString *)userId externalIdAuthToken:(NSString * _Nullable)externalIdAuthToken appId:(NSString *)appId withPurchases:(NSArray *)purchases; -+ (instancetype)withUserId:(NSString *)userId emailAuthToken:(NSString *)emailAuthToken appId:(NSString *)appId withPurchases:(NSArray *)purchases; -@end - @interface OSRequestSubmitNotificationOpened : OneSignalRequest + (instancetype)withUserId:(NSString *)userId appId:(NSString *)appId wasOpened:(BOOL)opened messageId:(NSString *)messageId withDeviceType:(NSNumber *)deviceType; @end -@interface OSRequestSyncHashedEmail : OneSignalRequest -+ (instancetype)withUserId:(NSString *)userId appId:(NSString *)appId email:(NSString *)email networkType:(NSNumber *)netType; -@end - NS_ASSUME_NONNULL_END -@interface OSRequestRegisterUser : OneSignalRequest -+ (instancetype _Nonnull)withData:(NSDictionary * _Nonnull)registrationData userId:(NSString * _Nullable)userId; -@end - -@interface OSRequestCreateDevice : OneSignalRequest -+ (instancetype _Nonnull)withAppId:(NSString * _Nonnull)appId withDeviceType:(NSNumber * _Nonnull)deviceType withEmail:(NSString * _Nullable)email withPlayerId:(NSString * _Nullable)playerId withEmailAuthHash:(NSString * _Nullable)emailAuthHash withExternalUserId:(NSString * _Nullable)externalUserId withExternalIdAuthToken:(NSString * _Nullable)externalIdAuthToken; - -+ (instancetype _Nonnull)withAppId:(NSString * _Nonnull)appId withDeviceType:(NSNumber * _Nonnull)deviceType withSMSNumber:(NSString * _Nullable)smsNumber withPlayerId:(NSString * _Nullable)playerId withSMSAuthHash:(NSString * _Nullable)smsAuthHash withExternalUserId:(NSString * _Nullable)externalUserId withExternalIdAuthToken:(NSString * _Nullable)externalIdAuthToken; -@end - -@interface OSRequestLogoutEmail : OneSignalRequest -+ (instancetype _Nonnull)withAppId:(NSString * _Nonnull)appId emailPlayerId:(NSString * _Nonnull)emailPlayerId devicePlayerId:(NSString * _Nonnull)devicePlayerId emailAuthHash:(NSString * _Nullable)emailAuthHash; -@end - -@interface OSRequestLogoutSMS : OneSignalRequest -+ (instancetype _Nonnull)withAppId:(NSString * _Nonnull)appId smsPlayerId:(NSString * _Nonnull)smsPlayerId smsAuthHash:(NSString * _Nullable)smsAuthHash devicePlayerId:(NSString * _Nonnull)devicePlayerId; -@end - -@interface OSRequestSendTagsToServer : OneSignalRequest -+ (instancetype _Nonnull)withUserId:(NSString * _Nonnull)userId appId:(NSString * _Nonnull)appId tags:(NSDictionary * _Nonnull)tags networkType:(NSNumber * _Nonnull)netType withEmailAuthHashToken:(NSString * _Nullable)emailAuthToken withExternalIdAuthHashToken:(NSString * _Nullable)externalIdAuthToken; - -+ (instancetype _Nonnull)withUserId:(NSString * _Nonnull)userId appId:(NSString * _Nonnull)appId tags:(NSDictionary * _Nonnull)tags networkType:(NSNumber * _Nonnull)netType withSMSAuthHashToken:(NSString * _Nullable)smsAuthToken withExternalIdAuthHashToken:(NSString * _Nullable)externalIdAuthToken; -@end - -@interface OSRequestUpdateLanguage : OneSignalRequest -+ (instancetype _Nonnull)withUserId:(NSString * _Nonnull)userId - appId:(NSString * _Nonnull)appId - language:(NSString * _Nonnull)language - emailAuthToken:(NSString * _Nullable)emailAuthHash - externalIdAuthToken:(NSString * _Nullable)externalIdAuthToken; - -+ (instancetype _Nonnull)withUserId:(NSString * _Nonnull)userId - appId:(NSString * _Nonnull)appId - language:(NSString * _Nonnull)language - smsAuthToken:(NSString * _Nullable)smsAuthToken - externalIdAuthToken:(NSString * _Nullable)externalIdAuthToken; -@end - -@interface OSRequestUpdateExternalUserId : OneSignalRequest -+ (instancetype _Nonnull)withUserId:(NSString * _Nullable)externalId withUserIdHashToken:(NSString * _Nullable)hashToken withOneSignalUserId:(NSString * _Nonnull)userId appId:(NSString * _Nonnull)appId; - -+ (instancetype _Nonnull)withUserId:(NSString * _Nullable)externalId withUserIdHashToken:(NSString * _Nullable)hashToken withOneSignalUserId:(NSString * _Nonnull)userId withEmailHashToken:(NSString * _Nullable)emailHashToken appId:(NSString * _Nonnull)appId; - -+ (instancetype _Nonnull)withUserId:(NSString * _Nullable)externalId withUserIdHashToken:(NSString * _Nullable)hashToken withOneSignalUserId:(NSString * _Nonnull)userId withSMSHashToken:(NSString * _Nullable)smsHashToken appId:(NSString * _Nonnull)appId; -@end - - @interface OSRequestTrackV1 : OneSignalRequest + (instancetype _Nonnull)trackUsageData:(NSString * _Nonnull)osUsageData appId:(NSString * _Nonnull)appId; diff --git a/iOS_SDK/OneSignalSDK/OneSignalCore/Source/API/OSRequests.m b/iOS_SDK/OneSignalSDK/OneSignalCore/Source/API/OSRequests.m index b20122f48..d3e7e0e00 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalCore/Source/API/OSRequests.m +++ b/iOS_SDK/OneSignalSDK/OneSignalCore/Source/API/OSRequests.m @@ -39,18 +39,6 @@ #import // SUBCLASSES - These subclasses each represent an individual request -@implementation OSRequestGetTags -+ (instancetype)withUserId:(NSString *)userId appId:(NSString *)appId { - let request = [OSRequestGetTags new]; - - request.parameters = @{@"app_id" : appId}; - request.method = GET; - request.path = [NSString stringWithFormat:@"players/%@", userId]; - request.disableLocalCaching = true; - - return request; -} -@end /* NOTE: The OSRequestGetIosParams request will not return a Cache-Control header @@ -78,39 +66,6 @@ -(BOOL)missingAppId { } @end -@implementation OSRequestSendTagsToServer -+ (instancetype _Nonnull)withUserId:(NSString * _Nonnull)userId appId:(NSString * _Nonnull)appId tags:(NSDictionary * _Nonnull)tags networkType:(NSNumber * _Nonnull)netType withEmailAuthHashToken:(NSString * _Nullable)emailAuthToken withExternalIdAuthHashToken:(NSString * _Nullable)externalIdAuthToken { - return [self withUserId:userId appId:appId tags:tags networkType:netType withAuthHashToken:emailAuthToken withAuthTokenKey:@"email_auth_hash" withExternalIdAuthHashToken:externalIdAuthToken]; -} - -+ (instancetype)withUserId:(NSString *)userId appId:(NSString *)appId tags:(NSDictionary *)tags networkType:(NSNumber *)netType withSMSAuthHashToken:(NSString *)smsAuthToken withExternalIdAuthHashToken:(NSString *)externalIdAuthToken { - return [self withUserId:userId appId:appId tags:tags networkType:netType withAuthHashToken:smsAuthToken withAuthTokenKey:@"sms_auth_hash" withExternalIdAuthHashToken:externalIdAuthToken]; -} - -+ (instancetype)withUserId:(NSString *)userId appId:(NSString *)appId tags:(NSDictionary *)tags networkType:(NSNumber *)netType withAuthHashToken:(NSString *)authToken withAuthTokenKey:(NSString *)authTokenKey withExternalIdAuthHashToken:(NSString *)externalIdAuthToken { - let request = [OSRequestSendTagsToServer new]; - - let params = [NSMutableDictionary new]; - params[@"app_id"] = appId; - params[@"tags"] = tags; - params[@"net_type"] = netType; - - if (authToken && authToken.length > 0) - params[authTokenKey] = authToken; - - if (externalIdAuthToken && externalIdAuthToken.length > 0) - params[@"external_user_id_auth_hash"] = externalIdAuthToken; - - request.parameters = params; - request.method = PUT; - request.path = [NSString stringWithFormat:@"players/%@", userId]; - - return request; -} - - -@end - @implementation OSRequestPostNotification + (instancetype)withAppId:(NSString *)appId withJson:(NSMutableDictionary *)json { let request = [OSRequestPostNotification new]; @@ -126,113 +81,6 @@ + (instancetype)withAppId:(NSString *)appId withJson:(NSMutableDictionary *)json } @end -@implementation OSRequestCreateDevice -+ (instancetype _Nonnull)withAppId:(NSString * _Nonnull)appId withDeviceType:(NSNumber * _Nonnull)deviceType withEmail:(NSString * _Nullable)email withPlayerId:(NSString * _Nullable)playerId withEmailAuthHash:(NSString * _Nullable)emailAuthHash withExternalUserId: (NSString * _Nullable)externalUserId withExternalIdAuthToken:(NSString * _Nullable)externalIdAuthToken { - let request = [OSRequestCreateDevice new]; - - let params = [[NSMutableDictionary alloc] initWithDictionary:@{ - @"app_id" : appId, - @"device_type" : deviceType, - @"identifier" : email ?: [NSNull null], - @"email_auth_hash" : emailAuthHash ?: [NSNull null], - @"external_user_id_auth_hash" : externalIdAuthToken ?: [NSNull null], - @"device_player_id" : playerId ?: [NSNull null] - }]; - - if (externalUserId) { - params[@"external_user_id"] = externalUserId; - } - request.parameters = params; - request.method = POST; - request.path = @"players"; - - return request; -} - -+ (instancetype)withAppId:(NSString *)appId withDeviceType:(NSNumber *)deviceType withSMSNumber:(NSString *)smsNumber withPlayerId:(NSString *)playerId withSMSAuthHash:(NSString *)smsAuthHash withExternalUserId: (NSString * _Nullable)externalUserId withExternalIdAuthToken:(NSString *)externalIdAuthToken { - let request = [OSRequestCreateDevice new]; - - let params = [[NSMutableDictionary alloc] initWithDictionary:@{ - @"app_id" : appId, - @"device_type" : deviceType, - @"identifier" : smsNumber ?: [NSNull null], - SMS_NUMBER_AUTH_HASH_KEY : smsAuthHash ?: [NSNull null], - @"external_user_id_auth_hash" : externalIdAuthToken ?: [NSNull null], - @"device_player_id" : playerId ?: [NSNull null] - }]; - - if (externalUserId) { - params[@"external_user_id"] = externalUserId; - } - - request.parameters = params; - request.method = POST; - request.path = @"players"; - - return request; -} -@end - -@implementation OSRequestLogoutEmail - -+ (instancetype _Nonnull)withAppId:(NSString * _Nonnull)appId emailPlayerId:(NSString * _Nonnull)emailPlayerId devicePlayerId:(NSString * _Nonnull)devicePlayerId emailAuthHash:(NSString * _Nullable)emailAuthHash { - let request = [OSRequestLogoutEmail new]; - - request.parameters = @{ - @"parent_player_id" : emailPlayerId ?: [NSNull null], - @"email_auth_hash" : emailAuthHash ?: [NSNull null], - @"app_id" : appId - }; - - request.method = POST; - request.path = [NSString stringWithFormat:@"players/%@/email_logout", devicePlayerId]; - - return request; -} - -@end - -@implementation OSRequestUpdateNotificationTypes -+ (instancetype)withUserId:(NSString *)userId appId:(NSString *)appId notificationTypes:(NSNumber *)notificationTypes { - let request = [OSRequestUpdateNotificationTypes new]; - - request.parameters = @{@"app_id" : appId, @"notification_types" : notificationTypes}; - request.method = PUT; - request.path = [NSString stringWithFormat:@"players/%@", userId]; - - return request; -} -@end - -@implementation OSRequestSendPurchases -+ (instancetype)withUserId:(NSString *)userId externalIdAuthToken:(NSString * _Nullable)externalIdAuthToken appId:(NSString *)appId withPurchases:(NSArray *)purchases { - let request = [OSRequestSendPurchases new]; - - request.parameters = @{@"app_id" : appId, - @"purchases" : purchases, - @"external_user_id_auth_hash" : externalIdAuthToken ?: [NSNull null] - }; - request.method = POST; - request.path = [NSString stringWithFormat:@"players/%@/on_purchase", userId]; - - return request; -} - -+ (instancetype)withUserId:(NSString *)userId emailAuthToken:(NSString *)emailAuthToken appId:(NSString *)appId withPurchases:(NSArray *)purchases { - let request = [OSRequestSendPurchases new]; - - request.parameters = @{ - @"app_id" : appId, - @"purchases" : purchases, - @"email_auth_hash" : emailAuthToken ?: [NSNull null] - }; - request.method = POST; - request.path = [NSString stringWithFormat:@"players/%@/on_purchase", userId]; - - return request; -} -@end - @implementation OSRequestSubmitNotificationOpened + (instancetype)withUserId:(NSString *)userId appId:(NSString *)appId wasOpened:(BOOL)opened messageId:(NSString *)messageId withDeviceType:(nonnull NSNumber *)deviceType{ let request = [OSRequestSubmitNotificationOpened new]; @@ -245,117 +93,6 @@ + (instancetype)withUserId:(NSString *)userId appId:(NSString *)appId wasOpened: } @end -@implementation OSRequestRegisterUser -+ (instancetype _Nonnull)withData:(NSDictionary * _Nonnull)registrationData userId:(NSString * _Nullable)userId { - - let request = [OSRequestRegisterUser new]; - - request.parameters = registrationData; - request.method = POST; - request.path = userId ? [NSString stringWithFormat:@"players/%@/on_session", userId] : @"players"; - - return request; -} -@end - -@implementation OSRequestSyncHashedEmail -+ (instancetype)withUserId:(NSString *)userId appId:(NSString *)appId email:(NSString *)email networkType:(NSNumber *)netType { - let request = [OSRequestSyncHashedEmail new]; - - let lowerCase = [email lowercaseString]; - let md5Hash = [OneSignalCoreHelper hashUsingMD5:lowerCase]; - let sha1Hash = [OneSignalCoreHelper hashUsingSha1:lowerCase]; - - [OneSignalLog onesignalLog:ONE_S_LL_DEBUG message:[NSString stringWithFormat:@"%@ - MD5: %@, SHA1:%@", lowerCase, md5Hash, sha1Hash]]; - - request.parameters = @{@"app_id" : appId, @"em_m" : md5Hash, @"em_s" : sha1Hash, @"net_type" : netType}; - request.method = PUT; - request.path = [NSString stringWithFormat:@"players/%@", userId]; - - return request; -} -@end - -@implementation OSRequestUpdateLanguage - -+ (instancetype _Nonnull)withUserId:(NSString * _Nonnull)userId - appId:(NSString * _Nonnull)appId - language:(NSString * _Nonnull)language - emailAuthToken:(NSString * _Nullable)emailAuthHash - externalIdAuthToken:(NSString * _Nullable)externalIdAuthToken { - return [self withUserId:userId appId:appId language:language authToken:emailAuthHash authTokenKey:@"email_auth_hash" externalIdAuthToken:externalIdAuthToken]; -} - -+ (instancetype)withUserId:(NSString *)userId - appId:(NSString *)appId - language:(NSString *)language - smsAuthToken:(NSString *)smsAuthToken - externalIdAuthToken:(NSString *)externalIdAuthToken { - return [self withUserId:userId appId:appId language:language authToken:smsAuthToken authTokenKey:@"sms_auth_hash" externalIdAuthToken:externalIdAuthToken]; -} - -+ (instancetype)withUserId:(NSString *)userId - appId:(NSString *)appId - language:(NSString *)language - authToken:(NSString *)authToken - authTokenKey:(NSString *)authTokenKey - externalIdAuthToken:(NSString *)externalIdAuthToken { - let request = [OSRequestUpdateLanguage new]; - - [OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"Attempting Update to Language"]; - - let params = [NSMutableDictionary new]; - params[@"app_id"] = appId; - params[@"language"] = language; - - if (authToken && authToken.length > 0 && authTokenKey) - params[authTokenKey] = authToken; - - if (externalIdAuthToken && externalIdAuthToken.length > 0) - params[@"external_user_id_auth_hash"] = externalIdAuthToken; - - request.parameters = params; - request.method = PUT; - request.path = [NSString stringWithFormat:@"players/%@", userId]; - - return request; -} - -@end - -@implementation OSRequestUpdateExternalUserId -+ (instancetype _Nonnull)withUserId:(NSString * _Nullable)externalId withUserIdHashToken:(NSString * _Nullable)hashToken withOneSignalUserId:(NSString *)userId appId:(NSString *)appId { - return [self withUserId:externalId withUserIdHashToken:hashToken withOneSignalUserId:userId withChannelHashToken:nil withHashTokenKey:nil appId:appId]; -} - -+ (instancetype)withUserId:(NSString *)externalId withUserIdHashToken:(NSString *)hashToken withOneSignalUserId:(NSString *)userId withEmailHashToken:(NSString *)emailHashToken appId:(NSString *)appId { - return [self withUserId:externalId withUserIdHashToken:hashToken withOneSignalUserId:userId withChannelHashToken:emailHashToken withHashTokenKey:@"email_auth_hash" appId:appId]; -} - -+ (instancetype)withUserId:(NSString *)externalId withUserIdHashToken:(NSString *)hashToken withOneSignalUserId:(NSString *)userId withSMSHashToken:(NSString *)smsHashToken appId:(NSString *)appId { - return [self withUserId:externalId withUserIdHashToken:hashToken withOneSignalUserId:userId withChannelHashToken:smsHashToken withHashTokenKey:@"sms_auth_hash" appId:appId]; -} - -+ (instancetype)withUserId:(NSString *)externalId withUserIdHashToken:(NSString *)hashToken withOneSignalUserId:(NSString *)userId withChannelHashToken:(NSString *)channelHashToken withHashTokenKey:(NSString *)hashTokenKey appId:(NSString *)appId { - NSString *msg = [NSString stringWithFormat:@"App ID: %@, external ID: %@", appId, externalId]; - [OneSignalLog onesignalLog:ONE_S_LL_DEBUG message:msg]; - - let request = [OSRequestUpdateExternalUserId new]; - NSMutableDictionary *parametres = [NSMutableDictionary new]; - [parametres setObject:appId forKey:@"app_id"]; - [parametres setObject:externalId ?: @"" forKey:@"external_user_id"]; - if (hashToken && [hashToken length] > 0) - [parametres setObject:hashToken forKey:@"external_user_id_auth_hash"]; - if (channelHashToken && hashTokenKey) - [parametres setObject:channelHashToken forKey:hashTokenKey]; - request.parameters = parametres; - request.method = PUT; - request.path = [NSString stringWithFormat:@"players/%@", userId]; - - return request; -} -@end - @implementation OSRequestTrackV1 NSString * const OS_USAGE_DATA = @"OS-Usage-Data"; + (instancetype)trackUsageData:(NSString *)osUsageData appId:(NSString *)appId { From 01e1ad9e3d508a7a81609bf35008effb7c383a25 Mon Sep 17 00:00:00 2001 From: Nan Date: Thu, 29 Dec 2022 01:59:37 -0800 Subject: [PATCH 05/17] have a separate model store just for push sub * Motivation: push sub behaves differently from other subscriptions and is not cleared from the store when a user changes. Separate it into its own store so that the email and sms subscriptions stores can be cleared but the push subscription store is not. --- .../Source/OneSignalCommonDefines.h | 1 + .../OneSignalOSCore/Source/OSModelStore.swift | 14 ++----------- .../Source/OneSignalUserManagerImpl.swift | 20 ++++++++++++------- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/iOS_SDK/OneSignalSDK/OneSignalCore/Source/OneSignalCommonDefines.h b/iOS_SDK/OneSignalSDK/OneSignalCore/Source/OneSignalCommonDefines.h index 754c0ca52..4913ceb0c 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalCore/Source/OneSignalCommonDefines.h +++ b/iOS_SDK/OneSignalSDK/OneSignalCore/Source/OneSignalCommonDefines.h @@ -291,6 +291,7 @@ typedef enum {GET, POST, HEAD, PUT, DELETE, OPTIONS, CONNECT, TRACE, PATCH} HTTP #define OS_PROPERTIES_MODEL_KEY @"OS_PROPERTIES_MODEL_KEY" #define OS_PROPERTIES_MODEL_STORE_KEY @"OS_PROPERTIES_MODEL_STORE_KEY" #define OS_PUSH_SUBSCRIPTION_MODEL_KEY @"OS_PUSH_SUBSCRIPTION_MODEL_KEY" +#define OS_PUSH_SUBSCRIPTION_MODEL_STORE_KEY @"OS_PUSH_SUBSCRIPTION_MODEL_STORE_KEY" #define OS_SUBSCRIPTION_MODEL_STORE_KEY @"OS_SUBSCRIPTION_MODEL_STORE_KEY" #define OS_ADD_ALIAS_DELTA @"OS_ADD_ALIAS_DELTA" diff --git a/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSModelStore.swift b/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSModelStore.swift index 721304e55..9bdbb8182 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSModelStore.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSModelStore.swift @@ -126,18 +126,8 @@ open class OSModelStore: NSObject { When the User changes, the Subscription Model Store must remove all models. In contrast, it is not necessary for the Identity or Properties Model Stores to do so. */ - public func clearModelsFromStore(modelToKeepId: String?) { - // TODO: For now, uglily have param for model to keep as workaround for clearing all models except push sub - // When we have a new user, the subscription store should be cleared except for push sub - // That's currently the only model store we call this from. - if let modelToKeepId, - let modelToKeep = self.models[modelToKeepId] - { - self.models = [modelToKeepId: modelToKeep] - OneSignalUserDefaults.initShared().saveCodeableData(forKey: self.storeKey, withValue: self.models) - } else { - self.models = [:] - } + public func clearModelsFromStore() { + self.models = [:] } } diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift index 4aca05652..26d5c511c 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift @@ -140,15 +140,19 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager { return pushSubscriptionStateChangesObserver } - // has Identity, Properties, and Subscription Model Stores + // has Identity, Properties, Subscription, and Push Subscription Model Stores let identityModelStore = OSModelStore(changeSubscription: OSEventProducer(), storeKey: OS_IDENTITY_MODEL_STORE_KEY) let propertiesModelStore = OSModelStore(changeSubscription: OSEventProducer(), storeKey: OS_PROPERTIES_MODEL_STORE_KEY) + // Holds email and sms subscription models let subscriptionModelStore = OSModelStore(changeSubscription: OSEventProducer(), storeKey: OS_SUBSCRIPTION_MODEL_STORE_KEY) + // Holds a single push subscription model + let pushSubscriptionModelStore = OSModelStore(changeSubscription: OSEventProducer(), storeKey: OS_PUSH_SUBSCRIPTION_MODEL_STORE_KEY) // These must be initialized in init() let identityModelStoreListener: OSIdentityModelStoreListener let propertiesModelStoreListener: OSPropertiesModelStoreListener let subscriptionModelStoreListener: OSSubscriptionModelStoreListener + let pushSubscriptionModelStoreListener: OSSubscriptionModelStoreListener // has Property and Identity operation executors let propertyExecutor = OSPropertyOperationExecutor() @@ -159,6 +163,7 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager { self.identityModelStoreListener = OSIdentityModelStoreListener(store: identityModelStore) self.propertiesModelStoreListener = OSPropertiesModelStoreListener(store: propertiesModelStore) self.subscriptionModelStoreListener = OSSubscriptionModelStoreListener(store: subscriptionModelStore) + self.pushSubscriptionModelStoreListener = OSSubscriptionModelStoreListener(store: pushSubscriptionModelStore) } // TODO: This method is called A LOT, check if all calls are needed. @@ -180,7 +185,7 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager { // Corrupted state if any of these models exist without the others if let identityModel = identityModelStore.getModels()[OS_IDENTITY_MODEL_KEY], let propertiesModel = propertiesModelStore.getModels()[OS_PROPERTIES_MODEL_KEY], - let pushSubscription = subscriptionModelStore.getModels()[OS_PUSH_SUBSCRIPTION_MODEL_KEY] { + let pushSubscription = pushSubscriptionModelStore.getModels()[OS_PUSH_SUBSCRIPTION_MODEL_KEY] { _user = OSUserInternalImpl(identityModel: identityModel, propertiesModel: propertiesModel, pushSubscriptionModel: pushSubscription) } @@ -191,6 +196,7 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager { identityModelStoreListener.start() propertiesModelStoreListener.start() subscriptionModelStoreListener.start() + pushSubscriptionModelStoreListener.start() // Setup the executors OSUserExecutor.start() @@ -226,7 +232,7 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager { } } - let pushSubscriptionModel = subscriptionModelStore.getModel(key: OS_PUSH_SUBSCRIPTION_MODEL_KEY) + let pushSubscriptionModel = pushSubscriptionModelStore.getModel(key: OS_PUSH_SUBSCRIPTION_MODEL_KEY) prepareForNewUser() let newUser = setNewInternalUser(externalId: externalId, pushSubscriptionModel: pushSubscriptionModel) @@ -251,7 +257,7 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager { let identityModelToIdentify = currentUser.identityModel // Immediately drop the old user and set a new user in the SDK - let pushSubscriptionModel = subscriptionModelStore.getModel(key: OS_PUSH_SUBSCRIPTION_MODEL_KEY) + let pushSubscriptionModel = pushSubscriptionModelStore.getModel(key: OS_PUSH_SUBSCRIPTION_MODEL_KEY) prepareForNewUser() let newUser = setNewInternalUser(externalId: externalId, pushSubscriptionModel: pushSubscriptionModel) @@ -313,7 +319,7 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager { NotificationCenter.default.post(name: Notification.Name(OS_ON_USER_WILL_CHANGE), object: nil) // This store MUST be cleared, Identity and Properties do not. - subscriptionModelStore.clearModelsFromStore(modelToKeepId: OS_PUSH_SUBSCRIPTION_MODEL_KEY) + subscriptionModelStore.clearModelsFromStore() } /** @@ -338,8 +344,8 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager { let pushSubscription = pushSubscriptionModel ?? createDefaultPushSubscription() // Add pushSubscription to store if not present - if (!subscriptionModelStore.getModels().keys.contains(OS_PUSH_SUBSCRIPTION_MODEL_KEY)) { - subscriptionModelStore.add(id: OS_PUSH_SUBSCRIPTION_MODEL_KEY, model: pushSubscription) + if (!pushSubscriptionModelStore.getModels().keys.contains(OS_PUSH_SUBSCRIPTION_MODEL_KEY)) { + pushSubscriptionModelStore.add(id: OS_PUSH_SUBSCRIPTION_MODEL_KEY, model: pushSubscription) } _user = OSUserInternalImpl(identityModel: identityModel, propertiesModel: propertiesModel, pushSubscriptionModel: pushSubscription) From ffebc250d36dcf23d25e42c9a8ff75ba09a721ad Mon Sep 17 00:00:00 2001 From: Nan Date: Thu, 29 Dec 2022 02:03:35 -0800 Subject: [PATCH 06/17] add hydrating check when a model is added to store * Motivation: hydrating subscriptions can create a model and add to store if it doesn't exist locally. Guard against hydrating here as well so that a request isn't extraneously created. --- .../OneSignalOSCore/Source/OSModelStore.swift | 8 ++++++-- .../OneSignalUser/Source/OSUserRequests.swift | 3 +-- .../Source/OneSignalUserManagerImpl.swift | 10 +++++----- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSModelStore.swift b/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSModelStore.swift index 9bdbb8182..1480dbe63 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSModelStore.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSModelStore.swift @@ -71,7 +71,7 @@ open class OSModelStore: NSObject { return self.models } - public func add(id: String, model: TModel) { + public func add(id: String, model: TModel, hydrating: Bool) { OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OSModelStore add() called with model \(model)") // TODO: Check if we are adding the same model? Do we replace? // For example, calling addEmail multiple times with the same email @@ -82,7 +82,11 @@ open class OSModelStore: NSObject { // listen for changes to this model model.changeNotifier.subscribe(self) - + + guard !hydrating else { + return + } + self.changeSubscription.fire { modelStoreListener in modelStoreListener.onAdded(model) } diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSUserRequests.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSUserRequests.swift index 1aa732150..e5e7da14a 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSUserRequests.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSUserRequests.swift @@ -113,14 +113,13 @@ class OSUserExecutor { } else { // This subscription does not exist in the store, add - // TODO: This creates a Delta and sends a request when it should be hydrating OneSignalUserManagerImpl.sharedInstance.subscriptionModelStore.add(id: address, model: OSSubscriptionModel( type: type, address: subModel["token"] as? String, subscriptionId: subModel["id"] as? String, accepted: true, isDisabled: false, - changeNotifier: OSEventProducer()) + changeNotifier: OSEventProducer()), hydrating: true ) } } diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift index 26d5c511c..c6fc487db 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift @@ -334,10 +334,10 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager { } let identityModel = OSIdentityModel(aliases: aliases, changeNotifier: OSEventProducer()) - self.identityModelStore.add(id: OS_IDENTITY_MODEL_KEY, model: identityModel) + self.identityModelStore.add(id: OS_IDENTITY_MODEL_KEY, model: identityModel, hydrating: false) let propertiesModel = OSPropertiesModel(changeNotifier: OSEventProducer()) - self.propertiesModelStore.add(id: OS_PROPERTIES_MODEL_KEY, model: propertiesModel) + self.propertiesModelStore.add(id: OS_PROPERTIES_MODEL_KEY, model: propertiesModel, hydrating: false) // TODO: We will have to save subscription_id and push_token to user defaults when we get them @@ -345,7 +345,7 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager { // Add pushSubscription to store if not present if (!pushSubscriptionModelStore.getModels().keys.contains(OS_PUSH_SUBSCRIPTION_MODEL_KEY)) { - pushSubscriptionModelStore.add(id: OS_PUSH_SUBSCRIPTION_MODEL_KEY, model: pushSubscription) + pushSubscriptionModelStore.add(id: OS_PUSH_SUBSCRIPTION_MODEL_KEY, model: pushSubscription, hydrating: false) } _user = OSUserInternalImpl(identityModel: identityModel, propertiesModel: propertiesModel, pushSubscriptionModel: pushSubscription) @@ -558,7 +558,7 @@ extension OneSignalUserManagerImpl: OSUser { isDisabled: false, changeNotifier: OSEventProducer() ) - self.subscriptionModelStore.add(id: email, model: model) + self.subscriptionModelStore.add(id: email, model: model, hydrating: false) } /** @@ -590,7 +590,7 @@ extension OneSignalUserManagerImpl: OSUser { isDisabled: false, changeNotifier: OSEventProducer() ) - self.subscriptionModelStore.add(id: number, model: model) + self.subscriptionModelStore.add(id: number, model: model, hydrating: false) } /** From 8689a9e07ffab93260bc0c12a8f956379851b089 Mon Sep 17 00:00:00 2001 From: Nan Date: Thu, 29 Dec 2022 13:29:20 -0800 Subject: [PATCH 07/17] fix push sub hydration logic (still faulty) * Motivation: Hydrating the push subscription is problematic. We will hydrate it if: - the push subscription ID does not already exist locally - the type of the returned subscription is iOSPush - the token at the time the request is made matches the returned token - we hydrate using the first matching subscription that is returned (there may be multiple iOS push subscriptions in the response but we will accept the first one that fulfills our conditions above) * This can still be faulty behavior but we get as close as we can to correct behavior for now. --- .../OneSignalUser/Source/OSUserRequests.swift | 45 +++++++++++-------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSUserRequests.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSUserRequests.swift index e5e7da14a..205bdee43 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSUserRequests.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSUserRequests.swift @@ -63,26 +63,31 @@ class OSUserExecutor { } /** - Used to parse Create User and Fetch User responses. + Used to parse Create User and Fetch User responses. The `originalPushToken` is the push token when the request was created, which may be different from the push token currently in the SDK (How again can that happen?). This is used to determine whether or not to hydrate the push subscription. */ - static func parseFetchUserResponse(response: [AnyHashable:Any], identityModel: OSIdentityModel) { + static func parseFetchUserResponse(response: [AnyHashable:Any], identityModel: OSIdentityModel, originalPushToken: String?) { // On success, 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 let modelInStore = OneSignalUserManagerImpl.sharedInstance.identityModelStore.getModel(key: OS_IDENTITY_MODEL_KEY) - // TODO: Determine if we should be hydrating the push sub if sub_id exists in the SDK. I think not, revisit. - // Only hydrate the push subscription ID if it does not exist in the SDK - if (OneSignalUserManagerImpl.sharedInstance.user.pushSubscriptionModel.subscriptionId == nil) { - if let subscriptionObject = parseSubscriptionObjectResponse(response) { - for subModel in subscriptionObject { - if let subType = subModel["type"] as? String { - if subType == "iOSPush" { - OneSignalUserManagerImpl.sharedInstance.user.pushSubscriptionModel.hydrate(subModel) - if let subId = subModel["id"] as? String { - OSNotificationsManager.setPushSubscriptionId(subId) - } - } + // TODO: Determine how to hydrate the push subscription, which is still faulty. + // Hydrate by token if sub_id exists? + // Problem: a user can have multiple iOS push subscription, and perhaps missing token + // Ideally we only get push subscription for this device in the response, not others + + // Hydrate the push subscription if we don't already have a subscription ID AND token matches the original request + if (OneSignalUserManagerImpl.sharedInstance.user.pushSubscriptionModel.subscriptionId == nil), + let subscriptionObject = parseSubscriptionObjectResponse(response) + { + for subModel in subscriptionObject { + if subModel["type"] as? String == "iOSPush", + subModel["token"] as? String == originalPushToken + { + OneSignalUserManagerImpl.sharedInstance.user.pushSubscriptionModel.hydrate(subModel) + if let subId = subModel["id"] as? String { + OSNotificationsManager.setPushSubscriptionId(subId) } + break; } } } @@ -104,8 +109,9 @@ class OSUserExecutor { let models = OneSignalUserManagerImpl.sharedInstance.subscriptionModelStore.getModels() for subModel in subscriptionObject { if let address = subModel["token"] as? String, - let type = OSSubscriptionType(rawValue: subModel["type"] as? String ?? ""), - subModel["type"] as? String != "iOSPush" + let rawType = subModel["type"] as? String, + rawType != "iOSPush", + let type = OSSubscriptionType(rawValue: rawType) { if let model = models[address] { // This subscription exists in the store, hydrate @@ -115,7 +121,7 @@ class OSUserExecutor { // This subscription does not exist in the store, add OneSignalUserManagerImpl.sharedInstance.subscriptionModelStore.add(id: address, model: OSSubscriptionModel( type: type, - address: subModel["token"] as? String, + address: address, subscriptionId: subModel["id"] as? String, accepted: true, isDisabled: false, @@ -141,6 +147,7 @@ class OSUserExecutor { // We will pass minimal properties to this request static func createUser(_ user: OSUserInternal) { + let originalPushToken = user.pushSubscriptionModel.address let request = OSRequestCreateUser(identityModel: user.identityModel, pushSubscriptionModel: user.pushSubscriptionModel) // Currently there are no requirements needed before sending this request @@ -149,7 +156,7 @@ class OSUserExecutor { } OneSignalClient.shared().execute(request) { response in if let response = response { - parseFetchUserResponse(response: response, identityModel: request.identityModel) + parseFetchUserResponse(response: response, identityModel: request.identityModel, originalPushToken: originalPushToken) } executePendingRequests() } onFailure: { error in @@ -237,7 +244,7 @@ class OSUserExecutor { OneSignalClient.shared().execute(request) { response in if let response = response { - parseFetchUserResponse(response: response, identityModel: request.identityModel) + parseFetchUserResponse(response: response, identityModel: request.identityModel, originalPushToken: OneSignalUserManagerImpl.sharedInstance.token) } } onFailure: { _ in // What? From d84070d6bcc77c1441da9a979f581bab2f02a0dc Mon Sep 17 00:00:00 2001 From: Nan Date: Mon, 2 Jan 2023 18:07:39 -0800 Subject: [PATCH 08/17] [example app] observers, update bundle ID * Add push subscription observer and permission observer * Missed this requirement for testing -> update bundle ID to staging, needs to be `com.onesignal.example.staging` * Move set log level up to capture logs earlier. * Not making any structural changes to example app, but link some buttons to new methods like login, logout --- .../OneSignalDevApp/AppDelegate.h | 3 +-- .../OneSignalDevApp/AppDelegate.m | 20 +++++++++++-------- .../Base.lproj/Main.storyboard | 8 ++++---- .../OneSignalDevApp.entitlements | 2 +- .../OneSignalDevApp/ViewController.m | 7 +++++-- .../OneSignalDevAppClip.entitlements | 2 +- .../project.pbxproj | 12 +++++------ ...lNotificationServiceExtension.entitlements | 2 +- .../OneSignalUser/Source/OSUserRequests.swift | 2 +- 9 files changed, 32 insertions(+), 26 deletions(-) diff --git a/iOS_SDK/OneSignalDevApp/OneSignalDevApp/AppDelegate.h b/iOS_SDK/OneSignalDevApp/OneSignalDevApp/AppDelegate.h index 73cb6324f..6ca31e069 100644 --- a/iOS_SDK/OneSignalDevApp/OneSignalDevApp/AppDelegate.h +++ b/iOS_SDK/OneSignalDevApp/OneSignalDevApp/AppDelegate.h @@ -31,8 +31,7 @@ #import #import -// TODO: Add subscription observer -@interface AppDelegate : UIResponder +@interface AppDelegate : UIResponder @property (strong, nonatomic) UIWindow *window; diff --git a/iOS_SDK/OneSignalDevApp/OneSignalDevApp/AppDelegate.m b/iOS_SDK/OneSignalDevApp/OneSignalDevApp/AppDelegate.m index 5289bbe8b..39db439ce 100644 --- a/iOS_SDK/OneSignalDevApp/OneSignalDevApp/AppDelegate.m +++ b/iOS_SDK/OneSignalDevApp/OneSignalDevApp/AppDelegate.m @@ -50,11 +50,11 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( // [FIRApp configure]; NSLog(@"Bundle URL: %@", [[NSBundle mainBundle] bundleURL]); + [OneSignal.Debug setLogLevel:ONE_S_LL_VERBOSE]; + [OneSignal.Debug setVisualLevel:ONE_S_LL_NONE]; [OneSignal initialize:[AppDelegate getOneSignalAppId] withLaunchOptions:launchOptions]; - [OneSignal.Debug setLogLevel:ONE_S_LL_VERBOSE]; - [OneSignal.Debug setVisualLevel:ONE_S_LL_NONE]; _notificationDelegate = [OneSignalNotificationCenterDelegate new]; id openNotificationHandler = ^(OSNotificationOpenedResult *result) { @@ -94,6 +94,11 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( [OneSignal.Notifications setNotificationWillShowInForegroundHandler:notificationReceiverBlock]; [OneSignal.Notifications setNotificationOpenedHandler:openNotificationHandler]; + OSPushSubscriptionState* state = [OneSignal.User.pushSubscription addObserver:self]; + NSLog(@"OneSignal Demo App push subscription observer added, current state: %@", state); + + [OneSignal.Notifications addPermissionObserver:self]; + NSLog(@"UNUserNotificationCenter.delegate: %@", UNUserNotificationCenter.currentNotificationCenter.delegate); return YES; @@ -120,12 +125,11 @@ - (void) onOSPermissionChanged:(OSPermissionStateChanges*)stateChanges { NSLog(@"onOSPermissionChanged: %@", stateChanges); } -// TODO: Add push sub observer -//- (void) onOSSubscriptionChanged:(OSSubscriptionStateChanges*)stateChanges { -// NSLog(@"onOSSubscriptionChanged: %@", stateChanges); -// ViewController* mainController = (ViewController*) self.window.rootViewController; -// mainController.subscriptionSegmentedControl.selectedSegmentIndex = (NSInteger) stateChanges.to.isSubscribed; -//} +- (void)onOSPushSubscriptionChangedWithStateChanges:(OSPushSubscriptionStateChanges *)stateChanges { + NSLog(@"onOSPushSubscriptionChangedWithStateChanges: %@", stateChanges); + ViewController* mainController = (ViewController*) self.window.rootViewController; + mainController.subscriptionSegmentedControl.selectedSegmentIndex = (NSInteger) stateChanges.to.optedIn; +} #pragma mark OSInAppMessageDelegate diff --git a/iOS_SDK/OneSignalDevApp/OneSignalDevApp/Base.lproj/Main.storyboard b/iOS_SDK/OneSignalDevApp/OneSignalDevApp/Base.lproj/Main.storyboard index ee8598ef5..323d8ebd3 100644 --- a/iOS_SDK/OneSignalDevApp/OneSignalDevApp/Base.lproj/Main.storyboard +++ b/iOS_SDK/OneSignalDevApp/OneSignalDevApp/Base.lproj/Main.storyboard @@ -43,7 +43,7 @@ - + @@ -298,7 +298,7 @@ - + @@ -374,11 +374,11 @@ -