From 21ed81329436f7d2889d3195bacc92a04171c0f1 Mon Sep 17 00:00:00 2001 From: Nan Date: Sat, 30 May 2026 15:25:12 -0700 Subject: [PATCH 1/5] refactor: route identifier reads through OneSignalIdentifiers Add OneSignalIdentifiers in OneSignalOSCore with storedAppId and storedSubscriptionId accessors backed by shared UserDefaults. Migrate six call sites; drop the now-dead OSUD_APP_ID write to initStandard. --- .../OneSignal.xcodeproj/project.pbxproj | 34 +++++++++++++ ...ignalNotificationServiceExtensionHandler.m | 6 +-- .../OneSignalReceiveReceiptsController.m | 6 +-- .../OSNotificationsManager.m | 3 +- .../Source/OneSignalIdentifiers.swift | 48 +++++++++++++++++++ .../Source/OneSignalUserManagerImpl.swift | 2 +- iOS_SDK/OneSignalSDK/Source/OneSignal.m | 29 ++++------- 7 files changed, 99 insertions(+), 29 deletions(-) create mode 100644 iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OneSignalIdentifiers.swift diff --git a/iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj b/iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj index 026d1027c..6d8831eab 100644 --- a/iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj +++ b/iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj @@ -94,6 +94,9 @@ 3C5501402E09CF0100E77DF7 /* OSCopyOnWriteSet.h in Headers */ = {isa = PBXBuildFile; fileRef = 3C55013E2E09CF0100E77DF7 /* OSCopyOnWriteSet.h */; }; 3C5501412E09CF0100E77DF7 /* OSCopyOnWriteSet.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C55013F2E09CF0100E77DF7 /* OSCopyOnWriteSet.m */; }; 3C5501432E09F3D900E77DF7 /* LoggingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C5501422E09F3D900E77DF7 /* LoggingTests.swift */; }; + 3C5C6FFC2FCB8DED00102E2C /* OneSignalIdentifiers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C5C6FFB2FCB8DED00102E2C /* OneSignalIdentifiers.swift */; }; + 3C5C6FFD2FCB933100102E2C /* OneSignalOSCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3C115161289A259500565C41 /* OneSignalOSCore.framework */; }; + 3C5C70022FCB935000102E2C /* OneSignalOSCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3C115161289A259500565C41 /* OneSignalOSCore.framework */; }; 3C60BB9B2ECF860600C765F7 /* OneSignalInAppMessages.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DEBAAE282A4211D900BF2C1C /* OneSignalInAppMessages.framework */; }; 3C60BB9C2ECF860600C765F7 /* OneSignalInAppMessages.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = DEBAAE282A4211D900BF2C1C /* OneSignalInAppMessages.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 3C62999F2BEEA34800649187 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 3C62999E2BEEA34800649187 /* PrivacyInfo.xcprivacy */; }; @@ -665,6 +668,20 @@ remoteGlobalIDString = 3C115160289A259500565C41; remoteInfo = OneSignalOSCore; }; + 3C5C6FFF2FCB933100102E2C /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 37747F8B19147D6400558FAD /* Project object */; + proxyType = 1; + remoteGlobalIDString = 3C115160289A259500565C41; + remoteInfo = OneSignalOSCore; + }; + 3C5C70042FCB935000102E2C /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 37747F8B19147D6400558FAD /* Project object */; + proxyType = 1; + remoteGlobalIDString = 3C115160289A259500565C41; + remoteInfo = OneSignalOSCore; + }; 3C60BB9D2ECF860600C765F7 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 37747F8B19147D6400558FAD /* Project object */; @@ -1330,6 +1347,7 @@ 3C55013E2E09CF0100E77DF7 /* OSCopyOnWriteSet.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OSCopyOnWriteSet.h; sourceTree = ""; }; 3C55013F2E09CF0100E77DF7 /* OSCopyOnWriteSet.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OSCopyOnWriteSet.m; sourceTree = ""; }; 3C5501422E09F3D900E77DF7 /* LoggingTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoggingTests.swift; sourceTree = ""; }; + 3C5C6FFB2FCB8DED00102E2C /* OneSignalIdentifiers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OneSignalIdentifiers.swift; sourceTree = ""; }; 3C62999E2BEEA34800649187 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = ""; }; 3C6299A02BEEA38100649187 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = ""; }; 3C6299A22BEEA3CC00649187 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = ""; }; @@ -1964,6 +1982,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 3C5C70022FCB935000102E2C /* OneSignalOSCore.framework in Frameworks */, DE7D1846270286C6002D3A5D /* OneSignalCore.framework in Frameworks */, DE7D18D22703ADE0002D3A5D /* OneSignalOutcomes.framework in Frameworks */, DE7D1843270283B9002D3A5D /* UserNotifications.framework in Frameworks */, @@ -2048,6 +2067,7 @@ DEF7845F2912EA0D00A1F3A5 /* UserNotifications.framework in Frameworks */, DEF784612912F5E100A1F3A5 /* UIKit.framework in Frameworks */, DEF784422912E16F00A1F3A5 /* OneSignalCore.framework in Frameworks */, + 3C5C6FFD2FCB933100102E2C /* OneSignalOSCore.framework in Frameworks */, DE2D8F4A2947D86200844084 /* OneSignalOutcomes.framework in Frameworks */, DE2D8F452947D85800844084 /* OneSignalExtension.framework in Frameworks */, ); @@ -2203,6 +2223,7 @@ 5BC1DE652C90BC9F00CA8807 /* Consistency */, 3C115163289A259500565C41 /* OneSignalOSCore.h */, 3C115188289ADEA300565C41 /* OSModelStore.swift */, + 3C5C6FFB2FCB8DED00102E2C /* OneSignalIdentifiers.swift */, 3C115186289ADE7700565C41 /* OSModelStoreListener.swift */, 3C115184289ADE4F00565C41 /* OSModel.swift */, 3CF1A5622C669EA40056B3AA /* OSNewRecordsState.swift */, @@ -3756,6 +3777,7 @@ dependencies = ( DE7D181B27026BEC002D3A5D /* PBXTargetDependency */, DE7D18D52703ADE0002D3A5D /* PBXTargetDependency */, + 3C5C70052FCB935000102E2C /* PBXTargetDependency */, ); name = OneSignalExtension; productName = OneSignalExtension; @@ -3888,6 +3910,7 @@ DEF784452912E16F00A1F3A5 /* PBXTargetDependency */, DE2D8F482947D85800844084 /* PBXTargetDependency */, DE2D8F4D2947D86200844084 /* PBXTargetDependency */, + 3C5C70002FCB933100102E2C /* PBXTargetDependency */, ); name = OneSignalNotifications; productName = OneSignalNotifications; @@ -4350,6 +4373,7 @@ 3C115165289A259500565C41 /* OneSignalOSCore.docc in Sources */, 5BC1DE5E2C90B80E00CA8807 /* OSCondition.swift in Sources */, 5BC1DE5C2C90B7E600CA8807 /* OSConsistencyManager.swift in Sources */, + 3C5C6FFC2FCB8DED00102E2C /* OneSignalIdentifiers.swift in Sources */, 3C115189289ADEA300565C41 /* OSModelStore.swift in Sources */, 3C115185289ADE4F00565C41 /* OSModel.swift in Sources */, 3CF1A5632C669EA40056B3AA /* OSNewRecordsState.swift in Sources */, @@ -4795,6 +4819,16 @@ target = 3C115160289A259500565C41 /* OneSignalOSCore */; targetProxy = 3C115199289AF86C00565C41 /* PBXContainerItemProxy */; }; + 3C5C70002FCB933100102E2C /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 3C115160289A259500565C41 /* OneSignalOSCore */; + targetProxy = 3C5C6FFF2FCB933100102E2C /* PBXContainerItemProxy */; + }; + 3C5C70052FCB935000102E2C /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 3C115160289A259500565C41 /* OneSignalOSCore */; + targetProxy = 3C5C70042FCB935000102E2C /* PBXContainerItemProxy */; + }; 3C60BB9E2ECF860600C765F7 /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = DEBAAE272A4211D900BF2C1C /* OneSignalInAppMessages */; diff --git a/iOS_SDK/OneSignalSDK/OneSignalExtension/OneSignalNotificationServiceExtensionHandler.m b/iOS_SDK/OneSignalSDK/OneSignalExtension/OneSignalNotificationServiceExtensionHandler.m index 84273fe38..381545340 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalExtension/OneSignalNotificationServiceExtensionHandler.m +++ b/iOS_SDK/OneSignalSDK/OneSignalExtension/OneSignalNotificationServiceExtensionHandler.m @@ -26,6 +26,7 @@ */ #import +#import #import "OSMacros.h" #import #import "OneSignalNotificationServiceExtensionHandler.h" @@ -140,9 +141,8 @@ + (void)onNotificationReceived:(NSString *)receivedNotificationId withBlockingTa [[OSSessionManager sharedSessionManager] onNotificationReceived:receivedNotificationId]; // Track confirmed delivery - let sharedUserDefaults = OneSignalUserDefaults.initShared; - let playerId = [sharedUserDefaults getSavedStringForKey:OSUD_PUSH_SUBSCRIPTION_ID defaultValue:nil]; - let appId = [sharedUserDefaults getSavedStringForKey:OSUD_APP_ID defaultValue:nil]; + NSString *playerId = OneSignalIdentifiers.subscriptionId; + NSString *appId = OneSignalIdentifiers.storedAppId; // Randomize send of confirmed deliveries to lessen traffic for high recipient notifications int randomDelay = semaphore != nil ? arc4random_uniform(MAX_CONF_DELIVERY_DELAY) : 0; [OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"OneSignal onNotificationReceived sendReceiveReceipt with delay: %i", randomDelay]]; diff --git a/iOS_SDK/OneSignalSDK/OneSignalExtension/OneSignalReceiveReceiptsController.m b/iOS_SDK/OneSignalSDK/OneSignalExtension/OneSignalReceiveReceiptsController.m index 86e1db286..560ae245b 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalExtension/OneSignalReceiveReceiptsController.m +++ b/iOS_SDK/OneSignalSDK/OneSignalExtension/OneSignalReceiveReceiptsController.m @@ -28,6 +28,7 @@ #import #import "OneSignalReceiveReceiptsController.h" #import +#import #import "OSMacros.h" #import "OneSignalExtensionRequests.h" @@ -38,9 +39,8 @@ - (BOOL)isReceiveReceiptsEnabled { } - (void)sendReceiveReceiptWithNotificationId:(NSString *)notificationId { - let sharedUserDefaults = OneSignalUserDefaults.initShared; - let playerId = [sharedUserDefaults getSavedStringForKey:OSUD_PUSH_SUBSCRIPTION_ID defaultValue:nil]; - let appId = [sharedUserDefaults getSavedStringForKey:OSUD_APP_ID defaultValue:nil]; + NSString *playerId = OneSignalIdentifiers.subscriptionId; + NSString *appId = OneSignalIdentifiers.storedAppId; [self sendReceiveReceiptWithPlayerId:playerId notificationId:notificationId diff --git a/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.m b/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.m index d1e44de81..757e609b8 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.m +++ b/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.m @@ -27,6 +27,7 @@ of this software and associated documentation files (the "Software"), to deal #import "OSNotificationsManager.h" #import +#import #import "OSMacros.h" #import #import @@ -234,7 +235,7 @@ + (NSString*)pushToken { static NSString *_pushSubscriptionId; + (NSString*)pushSubscriptionId { if (!_pushSubscriptionId) { - _pushSubscriptionId = [OneSignalUserDefaults.initShared getSavedStringForKey:OSUD_PUSH_SUBSCRIPTION_ID defaultValue:nil]; + _pushSubscriptionId = OneSignalIdentifiers.subscriptionId; } return _pushSubscriptionId; } diff --git a/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OneSignalIdentifiers.swift b/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OneSignalIdentifiers.swift new file mode 100644 index 000000000..54fb464ef --- /dev/null +++ b/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OneSignalIdentifiers.swift @@ -0,0 +1,48 @@ +/* + Modified MIT License + + Copyright 2026 OneSignal + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + 1. The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + 2. All copies of substantial portions of the Software may only be used in connection + with services provided by OneSignal. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + */ + +import Foundation +import OneSignalCore + +/// Durable accessors for OneSignal identifiers persisted to shared UserDefaults. +/// Useful when the in-memory source isn't available, notably the NSE process +/// +/// Callers with access to the in-memory current value (main-app SDK code) +/// should continue to use that source +@objc(OneSignalIdentifiers) +public final class OneSignalIdentifiers: NSObject { + + /// Last-known persisted `app_id` from shared UserDefaults. Returns nil if absent. + @objc public static var storedAppId: String? { + return OneSignalUserDefaults.initShared().getSavedString(forKey: OSUD_APP_ID, defaultValue: nil) + } + + /// Persisted push `subscription_id` from shared UserDefaults. Returns nil if absent. + @objc public static var subscriptionId: String? { + return OneSignalUserDefaults.initShared().getSavedString(forKey: OSUD_PUSH_SUBSCRIPTION_ID, defaultValue: nil) + } +} diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift index 28b68d232..78977e737 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift @@ -500,7 +500,7 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager { let sharedUserDefaults = OneSignalUserDefaults.initShared() let reachable = OSNotificationsManager.currentPermissionState.reachable let token = sharedUserDefaults.getSavedString(forKey: OSUD_PUSH_TOKEN, defaultValue: nil) - let subscriptionId = subscriptionId ?? sharedUserDefaults.getSavedString(forKey: OSUD_PUSH_SUBSCRIPTION_ID, defaultValue: nil) + let subscriptionId = subscriptionId ?? OneSignalIdentifiers.subscriptionId return OSSubscriptionModel(type: .push, address: token, diff --git a/iOS_SDK/OneSignalSDK/Source/OneSignal.m b/iOS_SDK/OneSignalSDK/Source/OneSignal.m index bbdecb547..fd8a3446b 100755 --- a/iOS_SDK/OneSignalSDK/Source/OneSignal.m +++ b/iOS_SDK/OneSignalSDK/Source/OneSignal.m @@ -26,6 +26,7 @@ */ #import "OneSignalFramework.h" +#import #import "OneSignalInternal.h" #import "OneSignalTracker.h" #import "OneSignalTrackIAP.h" @@ -236,17 +237,6 @@ + (void)initialize:(nonnull NSString*)newAppId withLaunchOptions:(nullable NSDic [self init]; } -+ (NSString * _Nullable)getCachedAppId { - let prevAppId = [OneSignalUserDefaults.initStandard getSavedStringForKey:OSUD_APP_ID defaultValue:nil]; - if (!prevAppId) { - [OneSignalLog onesignalLog:ONE_S_LL_INFO message:@"Waiting for setAppId(appId) with a valid appId to complete OneSignal init!"]; - } else { - let logMessage = [NSString stringWithFormat:@"Initializing OneSignal with cached appId: '%@'.", prevAppId]; - [OneSignalLog onesignalLog:ONE_S_LL_INFO message:logMessage]; - } - return prevAppId; -} - /* 1/2 steps in OneSignal init, relying on setLaunchOptions (usage order does not matter) Sets the app id OneSignal should use in the application @@ -257,10 +247,12 @@ + (void)setAppId:(nullable NSString*)newAppId { [OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"setAppId called with appId: %@!", newAppId]]; if (!newAppId || newAppId.length == 0) { - NSString* cachedAppId = [self getCachedAppId]; + NSString* cachedAppId = OneSignalIdentifiers.storedAppId; if (cachedAppId) { + [OneSignalLog onesignalLog:ONE_S_LL_INFO message:[NSString stringWithFormat:@"Initializing OneSignal with cached appId: '%@'.", cachedAppId]]; [OneSignalConfigManager setAppId:cachedAppId]; } else { + [OneSignalLog onesignalLog:ONE_S_LL_INFO message:@"Waiting for setAppId(appId) with a valid appId to complete OneSignal init!"]; return; } } else if ([OneSignalConfigManager getAppId] && ![newAppId isEqualToString:[OneSignalConfigManager getAppId]]) { @@ -533,7 +525,7 @@ + (void)handleAppIdChange:(NSString*)appId { } let standardUserDefaults = OneSignalUserDefaults.initStandard; - let prevAppId = [standardUserDefaults getSavedStringForKey:OSUD_APP_ID defaultValue:nil]; + NSString *prevAppId = OneSignalIdentifiers.storedAppId; // Handle changes to the app id, this might happen on a developer's device when testing // Will also run the first time OneSignal is initialized @@ -543,22 +535,17 @@ + (void)handleAppIdChange:(NSString*)appId { _didCallDownloadParameters = false; let sharedUserDefaults = OneSignalUserDefaults.initShared; - - [standardUserDefaults saveStringForKey:OSUD_APP_ID withValue:appId]; - + // Remove player_id from both standard and shared NSUserDefaults [standardUserDefaults removeValueForKey:OSUD_PUSH_SUBSCRIPTION_ID]; [sharedUserDefaults removeValueForKey:OSUD_PUSH_SUBSCRIPTION_ID]; [standardUserDefaults removeValueForKey:OSUD_LEGACY_PLAYER_ID]; [sharedUserDefaults removeValueForKey:OSUD_LEGACY_PLAYER_ID]; - + // Clear all cached data, does not start User Module nor call logout. [OneSignalUserManagerImpl.sharedInstance clearAllModelsFromStores]; } - - // Always save appId and player_id as it will not be present on shared if: - // - Updating from an older SDK - // - Updating to an app that didn't have App Groups setup before + [OneSignalUserDefaults.initShared saveStringForKey:OSUD_APP_ID withValue:appId]; } From 078913814b956aea442a609dc0407e2ca4dcc081 Mon Sep 17 00:00:00 2001 From: Nan Date: Sat, 30 May 2026 16:22:28 -0700 Subject: [PATCH 2/5] refactor: drop redundant OSNotificationsManager pushSubscriptionId cache MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit OSSubscriptionModel.subscriptionId.didSet already persists to UserDefaults on every change, so the static _pushSubscriptionId cache and its setter were duplicating state with drift risk. Route the one caller through OneSignalIdentifiers.subscriptionId directly. Drop the now-unused OSUserExecutor.setPushSubscriptionId call too — the model hydration on the line above already triggers the persistence path. --- .../OneSignalNotifications/OSNotificationsManager.h | 3 --- .../OneSignalNotifications/OSNotificationsManager.m | 13 +------------ .../Source/Executors/OSUserExecutor.swift | 7 ++----- 3 files changed, 3 insertions(+), 20 deletions(-) diff --git a/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.h b/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.h index cff6ac32b..d975043a1 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.h +++ b/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.h @@ -121,9 +121,6 @@ NS_SWIFT_NAME(onClick(event:)); @property (class, readonly) OneSignalNotificationSettings* _Nonnull osNotificationSettings; -// This is set by the user module -+ (void)setPushSubscriptionId:(NSString *_Nullable)pushSubscriptionId; - + (void)handleWillShowInForegroundForNotification:(OSNotification *_Nonnull)notification completion:(OSNotificationDisplayResponse _Nonnull)completion; + (void)handleNotificationActionWithUrl:(NSString* _Nullable)url actionID:(NSString* _Nonnull)actionID; + (void)clearBadgeCount:(BOOL)fromNotifOpened fromClearAll:(BOOL)fromClearAll; diff --git a/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.m b/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.m index 757e609b8..f887dd9af 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.m +++ b/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.m @@ -232,17 +232,6 @@ + (NSString*)pushToken { return _pushToken; } -static NSString *_pushSubscriptionId; -+ (NSString*)pushSubscriptionId { - if (!_pushSubscriptionId) { - _pushSubscriptionId = OneSignalIdentifiers.subscriptionId; - } - return _pushSubscriptionId; -} -+ (void)setPushSubscriptionId:(NSString *)pushSubscriptionId { - _pushSubscriptionId = pushSubscriptionId; -} - #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wundeclared-selector" + (void)startSwizzling { @@ -784,7 +773,7 @@ + (void)submitNotificationOpened:(NSString*)messageId { NSString* lastMessageId = [standardUserDefaults getSavedStringForKey:OSUD_LAST_MESSAGE_OPENED defaultValue:nil]; //Only submit request if messageId not nil and: (lastMessage is nil or not equal to current one) if(messageId && (!lastMessageId || ![lastMessageId isEqualToString:messageId])) { - [OneSignalCoreImpl.sharedClient executeRequest:[OSRequestSubmitNotificationOpened withUserId:[self pushSubscriptionId] + [OneSignalCoreImpl.sharedClient executeRequest:[OSRequestSubmitNotificationOpened withUserId:OneSignalIdentifiers.subscriptionId appId:[OneSignalConfigManager getAppId] wasOpened:YES messageId:messageId diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Executors/OSUserExecutor.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Executors/OSUserExecutor.swift index 0a8cc4f5b..6c2f3f0e2 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Executors/OSUserExecutor.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Executors/OSUserExecutor.swift @@ -528,11 +528,8 @@ extension OSUserExecutor { areTokensEqual(tokenA: originalPushToken, tokenB: subModel["token"] as? String) { OneSignalUserManagerImpl.sharedInstance.pushSubscriptionModel?.hydrate(subModel) - if let subId = subModel["id"] as? String { - OSNotificationsManager.setPushSubscriptionId(subId) - if addNewRecords { - newRecordsState.add(subId) - } + if addNewRecords, let subId = subModel["id"] as? String { + newRecordsState.add(subId) } break } From 597799ccd11795860360d15a674d5cacf3e03ad5 Mon Sep 17 00:00:00 2001 From: Nan Date: Sat, 30 May 2026 17:00:46 -0700 Subject: [PATCH 3/5] refactor: replace OneSignalConfigManager with OneSignalConfig + OneSignalIdentifiers.currentAppId MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit OneSignalConfigManager held two distinct things in one ObjC class in OneSignalCore: (1) the in-memory app_id state, and (2) the SDK-readiness predicate `shouldAwaitAppIdAndLogMissingPrivacyConsent`. Split into two Swift classes in OneSignalOSCore so all identifier accessors live in one module: - `OneSignalIdentifiers.currentAppId` — in-memory app_id, replaces `OneSignalConfigManager.getAppId/setAppId`. Sits next to the existing `storedAppId` (persisted) and `subscriptionId` (persisted) accessors. - `OneSignalConfig.shouldAwaitAppIdAndLogMissingPrivacyConsent` — same semantics, now reads `OneSignalIdentifiers.currentAppId` internally. Migrate ~30 call sites across OneSignalCore (umbrella), OneSignalOSCore, OneSignalUser, OneSignalLiveActivities, OneSignalNotifications, OneSignal- Location, OneSignalInAppMessages, OneSignalOutcomes, and the main OneSignal target. Link OneSignalOSCore.framework into OneSignalInAppMessages, One- SignalLocation, and OneSignalOutcomes targets (they didn't previously). --- .../OneSignal.xcodeproj/project.pbxproj | 27 ++++--- .../Source/OneSignalConfigManager.h | 36 ---------- .../OneSignalCore/Source/OneSignalCore.h | 1 - .../Controller/OSInAppMessageController.m | 5 +- .../Controller/OSMessagingController.m | 8 +-- .../Requests/OSInAppMessagingRequests.m | 3 +- .../EarlyTriggerTrackingTests.swift | 2 +- .../IAMIntegrationTests.swift | 4 +- .../OSMessagingControllerUserStateTests.swift | 2 +- .../OSRequestLiveActivityClicked.swift | 3 +- ...OSRequestLiveActivityReceiveReceipts.swift | 3 +- .../Requests/OSRequestRemoveStartToken.swift | 3 +- .../Requests/OSRequestRemoveUpdateToken.swift | 3 +- .../Requests/OSRequestSetStartToken.swift | 3 +- .../Requests/OSRequestSetUpdateToken.swift | 3 +- .../OSLiveActivitiesExecutorTests.swift | 3 +- .../OneSignalLocationManager.m | 3 +- ...plicationDelegate+OneSignalNotifications.m | 5 +- ...otificationCenter+OneSignalNotifications.m | 3 +- .../OSNotificationsManager.m | 6 +- .../Source/OSOperationRepo.swift | 8 +-- .../Source/OneSignalConfig.swift} | 49 ++++++------- .../Source/OneSignalIdentifiers.swift | 11 +++ .../OneSignalOutcomeEventsController.m | 7 +- .../Source/OneSignalUserManagerImpl.swift | 72 +++++++++---------- .../Source/Requests/OSRequestAddAliases.swift | 2 +- .../OSRequestCreateSubscription.swift | 2 +- .../Source/Requests/OSRequestCreateUser.swift | 2 +- .../Requests/OSRequestCustomEvents.swift | 2 +- .../OSRequestDeleteSubscription.swift | 2 +- ...OSRequestFetchIdentityBySubscription.swift | 2 +- .../Source/Requests/OSRequestFetchUser.swift | 2 +- .../Requests/OSRequestIdentifyUser.swift | 2 +- .../Requests/OSRequestRemoveAlias.swift | 2 +- .../Requests/OSRequestUpdateProperties.swift | 2 +- .../OSRequestUpdateSubscription.swift | 2 +- .../CustomEventsIntegrationTests.swift | 2 +- .../OSCustomEventsExecutorTests.swift | 2 +- .../Executors/UserExecutorTests.swift | 2 +- .../OneSignalUserObjcTests.m | 2 +- .../OneSignalUserTests.swift | 2 +- .../SwitchUserIntegrationTests.swift | 2 +- .../UserConcurrencyTests.swift | 2 +- iOS_SDK/OneSignalSDK/Source/OneSignal.m | 30 ++++---- .../Source/OneSignalLifecycleObserver.m | 7 +- .../OneSignalSDK/Source/OneSignalTracker.m | 3 +- 46 files changed, 172 insertions(+), 177 deletions(-) delete mode 100644 iOS_SDK/OneSignalSDK/OneSignalCore/Source/OneSignalConfigManager.h rename iOS_SDK/OneSignalSDK/{OneSignalCore/Source/OneSignalConfigManager.m => OneSignalOSCore/Source/OneSignalConfig.swift} (52%) diff --git a/iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj b/iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj index 6d8831eab..9adfba76f 100644 --- a/iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj +++ b/iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj @@ -87,8 +87,6 @@ 3C448B9F2936ADFD002F96BC /* OSBackgroundTaskHandlerImpl.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C448B9C2936ADFD002F96BC /* OSBackgroundTaskHandlerImpl.m */; }; 3C448BA02936ADFD002F96BC /* OSBackgroundTaskHandlerImpl.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C448B9C2936ADFD002F96BC /* OSBackgroundTaskHandlerImpl.m */; }; 3C448BA22936B474002F96BC /* OSBackgroundTaskManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C448BA12936B474002F96BC /* OSBackgroundTaskManager.swift */; }; - 3C47A974292642B100312125 /* OneSignalConfigManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 3C47A972292642B100312125 /* OneSignalConfigManager.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 3C47A975292642B100312125 /* OneSignalConfigManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C47A973292642B100312125 /* OneSignalConfigManager.m */; }; 3C4F9E4428A4466C009F453A /* OSOperationRepo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C4F9E4328A4466C009F453A /* OSOperationRepo.swift */; }; 3C5117172B15C31E00563465 /* OSUserState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C5117162B15C31E00563465 /* OSUserState.swift */; }; 3C5501402E09CF0100E77DF7 /* OSCopyOnWriteSet.h in Headers */ = {isa = PBXBuildFile; fileRef = 3C55013E2E09CF0100E77DF7 /* OSCopyOnWriteSet.h */; }; @@ -97,6 +95,8 @@ 3C5C6FFC2FCB8DED00102E2C /* OneSignalIdentifiers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C5C6FFB2FCB8DED00102E2C /* OneSignalIdentifiers.swift */; }; 3C5C6FFD2FCB933100102E2C /* OneSignalOSCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3C115161289A259500565C41 /* OneSignalOSCore.framework */; }; 3C5C70022FCB935000102E2C /* OneSignalOSCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3C115161289A259500565C41 /* OneSignalOSCore.framework */; }; + 3C5C70082FCBAA5C00102E2C /* OneSignalConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C5C70072FCBAA5C00102E2C /* OneSignalConfig.swift */; }; + 3C5C70092FCBB0F400102E2C /* OneSignalOSCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3C115161289A259500565C41 /* OneSignalOSCore.framework */; }; 3C60BB9B2ECF860600C765F7 /* OneSignalInAppMessages.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DEBAAE282A4211D900BF2C1C /* OneSignalInAppMessages.framework */; }; 3C60BB9C2ECF860600C765F7 /* OneSignalInAppMessages.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = DEBAAE282A4211D900BF2C1C /* OneSignalInAppMessages.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 3C62999F2BEEA34800649187 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 3C62999E2BEEA34800649187 /* PrivacyInfo.xcprivacy */; }; @@ -682,6 +682,13 @@ remoteGlobalIDString = 3C115160289A259500565C41; remoteInfo = OneSignalOSCore; }; + 3C5C700B2FCBB0F400102E2C /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 37747F8B19147D6400558FAD /* Project object */; + proxyType = 1; + remoteGlobalIDString = 3C115160289A259500565C41; + remoteInfo = OneSignalOSCore; + }; 3C60BB9D2ECF860600C765F7 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 37747F8B19147D6400558FAD /* Project object */; @@ -1340,14 +1347,13 @@ 3C448B9B2936ADFD002F96BC /* OSBackgroundTaskHandlerImpl.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OSBackgroundTaskHandlerImpl.h; sourceTree = ""; }; 3C448B9C2936ADFD002F96BC /* OSBackgroundTaskHandlerImpl.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OSBackgroundTaskHandlerImpl.m; sourceTree = ""; }; 3C448BA12936B474002F96BC /* OSBackgroundTaskManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSBackgroundTaskManager.swift; sourceTree = ""; }; - 3C47A972292642B100312125 /* OneSignalConfigManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OneSignalConfigManager.h; sourceTree = ""; }; - 3C47A973292642B100312125 /* OneSignalConfigManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OneSignalConfigManager.m; sourceTree = ""; }; 3C4F9E4328A4466C009F453A /* OSOperationRepo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSOperationRepo.swift; sourceTree = ""; }; 3C5117162B15C31E00563465 /* OSUserState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSUserState.swift; sourceTree = ""; }; 3C55013E2E09CF0100E77DF7 /* OSCopyOnWriteSet.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OSCopyOnWriteSet.h; sourceTree = ""; }; 3C55013F2E09CF0100E77DF7 /* OSCopyOnWriteSet.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OSCopyOnWriteSet.m; sourceTree = ""; }; 3C5501422E09F3D900E77DF7 /* LoggingTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoggingTests.swift; sourceTree = ""; }; 3C5C6FFB2FCB8DED00102E2C /* OneSignalIdentifiers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OneSignalIdentifiers.swift; sourceTree = ""; }; + 3C5C70072FCBAA5C00102E2C /* OneSignalConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OneSignalConfig.swift; sourceTree = ""; }; 3C62999E2BEEA34800649187 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = ""; }; 3C6299A02BEEA38100649187 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = ""; }; 3C6299A22BEEA3CC00649187 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = ""; }; @@ -1993,6 +1999,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 3C5C70092FCBB0F400102E2C /* OneSignalOSCore.framework in Frameworks */, DE7D188F27037F96002D3A5D /* OneSignalCore.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -2233,6 +2240,7 @@ 3C8E6DF828A6D89E0031E48A /* OSOperationExecutor.swift */, 3CE5F9E2289D88DC004A156E /* OSModelStoreChangedHandler.swift */, 3C2D8A5828B4C4E300BE41F6 /* OSDelta.swift */, + 3C5C70072FCBAA5C00102E2C /* OneSignalConfig.swift */, 3C448BA12936B474002F96BC /* OSBackgroundTaskManager.swift */, 4710EA522B8FCFB200435356 /* OSDispatchQueue.swift */, DEFB3E642BB7346D00E65DAD /* OSLiveActivities.swift */, @@ -2750,8 +2758,6 @@ 3C2DB2EF2DE6CB5E0006B905 /* OneSignalBadgeHelpers.h */, 3C2DB2F02DE6CB5E0006B905 /* OneSignalBadgeHelpers.m */, 3CE8CC4C2911ADD1000DB0D3 /* OSDeviceUtils.h */, - 3C47A972292642B100312125 /* OneSignalConfigManager.h */, - 3C47A973292642B100312125 /* OneSignalConfigManager.m */, 3CE8CC4D2911ADD1000DB0D3 /* OSDeviceUtils.m */, CA70E3382023F24500019273 /* OneSignalCommonDefines.h */, 7AD8DDE8234BD3CF00747A8A /* OneSignalUserDefaults.h */, @@ -3319,7 +3325,6 @@ 3C5501402E09CF0100E77DF7 /* OSCopyOnWriteSet.h in Headers */, DE971754274C48CF00FC409E /* OSPrivacyConsentController.h in Headers */, 3CE8CC4E2911ADD1000DB0D3 /* OSDeviceUtils.h in Headers */, - 3C47A974292642B100312125 /* OneSignalConfigManager.h in Headers */, DE7D183627027AA0002D3A5D /* OneSignalLog.h in Headers */, 3C44673F296D09CC0039A49E /* OneSignalMobileProvision.h in Headers */, 3CCF44BE299B17290021964D /* OneSignalWrapper.h in Headers */, @@ -3797,6 +3802,7 @@ ); dependencies = ( DE7D189227037F96002D3A5D /* PBXTargetDependency */, + 3C5C700C2FCBB0F400102E2C /* PBXTargetDependency */, ); name = OneSignalOutcomes; productName = OneSignalOutcomes; @@ -4380,6 +4386,7 @@ 3C448BA22936B474002F96BC /* OSBackgroundTaskManager.swift in Sources */, 5B58F09E2CC1B5C700298493 /* OSReadYourWriteData.swift in Sources */, 3C115187289ADE7700565C41 /* OSModelStoreListener.swift in Sources */, + 3C5C70082FCBAA5C00102E2C /* OneSignalConfig.swift in Sources */, 5BC1DE642C90BB9000CA8807 /* OSIamFetchReadyCondition.swift in Sources */, 3CE5F9E3289D88DC004A156E /* OSModelStoreChangedHandler.swift in Sources */, 3C2D8A5928B4C4E300BE41F6 /* OSDelta.swift in Sources */, @@ -4651,7 +4658,6 @@ DEBAAEB32A436CE800BF2C1C /* OSStubInAppMessages.m in Sources */, DEBA2A262C20E9AA00E234DB /* OSBundleUtils.m in Sources */, 3C70FA682D0B68A100031066 /* OneSignalClientError.m in Sources */, - 3C47A975292642B100312125 /* OneSignalConfigManager.m in Sources */, DE7D1874270375FF002D3A5D /* OSReattemptRequest.m in Sources */, DE7D183427027A73002D3A5D /* OneSignalLog.m in Sources */, DEF784642912FA5100A1F3A5 /* OSDialogInstanceManager.m in Sources */, @@ -4829,6 +4835,11 @@ target = 3C115160289A259500565C41 /* OneSignalOSCore */; targetProxy = 3C5C70042FCB935000102E2C /* PBXContainerItemProxy */; }; + 3C5C700C2FCBB0F400102E2C /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 3C115160289A259500565C41 /* OneSignalOSCore */; + targetProxy = 3C5C700B2FCBB0F400102E2C /* PBXContainerItemProxy */; + }; 3C60BB9E2ECF860600C765F7 /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = DEBAAE272A4211D900BF2C1C /* OneSignalInAppMessages */; diff --git a/iOS_SDK/OneSignalSDK/OneSignalCore/Source/OneSignalConfigManager.h b/iOS_SDK/OneSignalSDK/OneSignalCore/Source/OneSignalConfigManager.h deleted file mode 100644 index 481b16eee..000000000 --- a/iOS_SDK/OneSignalSDK/OneSignalCore/Source/OneSignalConfigManager.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - Modified MIT License - - Copyright 2022 OneSignal - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - 1. The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - 2. All copies of substantial portions of the Software may only be used in connection - with services provided by OneSignal. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - */ - -#import - -@interface OneSignalConfigManager : NSObject - -+ (void)setAppId:(NSString *)appId; -+ (NSString *_Nullable)getAppId; -+ (BOOL)shouldAwaitAppIdAndLogMissingPrivacyConsentForMethod:(NSString *)methodName; - -@end diff --git a/iOS_SDK/OneSignalSDK/OneSignalCore/Source/OneSignalCore.h b/iOS_SDK/OneSignalSDK/OneSignalCore/Source/OneSignalCore.h index c91e282e4..4c8cdc8ef 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalCore/Source/OneSignalCore.h +++ b/iOS_SDK/OneSignalSDK/OneSignalCore/Source/OneSignalCore.h @@ -49,7 +49,6 @@ #import #import #import -#import #import #import #import diff --git a/iOS_SDK/OneSignalSDK/OneSignalInAppMessages/Controller/OSInAppMessageController.m b/iOS_SDK/OneSignalSDK/OneSignalInAppMessages/Controller/OSInAppMessageController.m index bf42b381b..4609ea4d9 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalInAppMessages/Controller/OSInAppMessageController.m +++ b/iOS_SDK/OneSignalSDK/OneSignalInAppMessages/Controller/OSInAppMessageController.m @@ -27,6 +27,7 @@ #import "OSInAppMessageController.h" #import +#import #import "OSMacros.h" #import #import "OSInAppMessagingDefines.h" @@ -45,7 +46,7 @@ - (void)loadMessageHTMLContentWithResult:(OSResultSuccessBlock _Nullable)success return; } - let request = [OSRequestLoadInAppMessageContent withAppId:[OneSignalConfigManager getAppId] withMessageId:self.messageId withVariantId:variantId]; + let request = [OSRequestLoadInAppMessageContent withAppId:OneSignalIdentifiers.currentAppId withMessageId:self.messageId withVariantId:variantId]; [OneSignalCoreImpl.sharedClient executeRequest:request onSuccess:successBlock onFailure:^(OneSignalClientError *error) { failureBlock(error.underlyingError); @@ -53,7 +54,7 @@ - (void)loadMessageHTMLContentWithResult:(OSResultSuccessBlock _Nullable)success } - (void)loadPreviewMessageHTMLContentWithUUID:(NSString * _Nonnull)previewUUID success:(OSResultSuccessBlock _Nullable)successBlock failure:(OSFailureBlock _Nullable)failureBlock { - let request = [OSRequestLoadInAppMessagePreviewContent withAppId:[OneSignalConfigManager getAppId] previewUUID:previewUUID]; + let request = [OSRequestLoadInAppMessagePreviewContent withAppId:OneSignalIdentifiers.currentAppId previewUUID:previewUUID]; [OneSignalCoreImpl.sharedClient executeRequest:request onSuccess:successBlock onFailure:^(OneSignalClientError *error) { failureBlock(error.underlyingError); diff --git a/iOS_SDK/OneSignalSDK/OneSignalInAppMessages/Controller/OSMessagingController.m b/iOS_SDK/OneSignalSDK/OneSignalInAppMessages/Controller/OSMessagingController.m index ad65a2f9d..067787d89 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalInAppMessages/Controller/OSMessagingController.m +++ b/iOS_SDK/OneSignalSDK/OneSignalInAppMessages/Controller/OSMessagingController.m @@ -643,7 +643,7 @@ - (void)messageViewPageImpressionRequest:(OSInAppMessageInternal *)message withP [OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"Page Impression Request page id: %@",pageId]]; // Create the request and attach a payload to it - let metricsRequest = [OSRequestInAppMessagePageViewed withAppId:OneSignalConfigManager.getAppId + let metricsRequest = [OSRequestInAppMessagePageViewed withAppId:OneSignalIdentifiers.currentAppId withPlayerId:OneSignalUserManagerImpl.sharedInstance.pushSubscriptionId withMessageId:message.messageId withPageId:pageId @@ -683,7 +683,7 @@ - (void)messageViewImpressionRequest:(OSInAppMessageInternal *)message { [self.impressionedInAppMessages addObject:message.messageId]; // Create the request and attach a payload to it - let metricsRequest = [OSRequestInAppMessageViewed withAppId:OneSignalConfigManager.getAppId + let metricsRequest = [OSRequestInAppMessageViewed withAppId:OneSignalIdentifiers.currentAppId withPlayerId:OneSignalUserManagerImpl.sharedInstance.pushSubscriptionId withMessageId:message.messageId forVariantId:message.variantId]; @@ -1094,7 +1094,7 @@ - (void)sendClickRESTCall:(OSInAppMessageInternal *)message withAction:(OSInAppM // Track clickId per IAM [message addClickId:clickId]; - let metricsRequest = [OSRequestInAppMessageClicked withAppId:OneSignalConfigManager.getAppId + let metricsRequest = [OSRequestInAppMessageClicked withAppId:OneSignalIdentifiers.currentAppId withPlayerId:OneSignalUserManagerImpl.sharedInstance.pushSubscriptionId withMessageId:message.messageId forVariantId:message.variantId @@ -1140,7 +1140,7 @@ - (void)sendClickActionOutcomes:(NSArray *)outcomes { return; } - [OSOutcomes.sharedController sendClickActionOutcomes:outcomes appId:OneSignalConfigManager.getAppId deviceType:[NSNumber numberWithInt:DEVICE_TYPE_PUSH]]; + [OSOutcomes.sharedController sendClickActionOutcomes:outcomes appId:OneSignalIdentifiers.currentAppId deviceType:[NSNumber numberWithInt:DEVICE_TYPE_PUSH]]; } /* diff --git a/iOS_SDK/OneSignalSDK/OneSignalInAppMessages/Requests/OSInAppMessagingRequests.m b/iOS_SDK/OneSignalSDK/OneSignalInAppMessages/Requests/OSInAppMessagingRequests.m index dfb1babf8..6cf041dae 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalInAppMessages/Requests/OSInAppMessagingRequests.m +++ b/iOS_SDK/OneSignalSDK/OneSignalInAppMessages/Requests/OSInAppMessagingRequests.m @@ -25,6 +25,7 @@ of this software and associated documentation files (the "Software"), to deal THE SOFTWARE. */ #import +#import #import "OSInAppMessagingRequests.h" #import "OSMacros.h" @@ -54,7 +55,7 @@ + (instancetype _Nonnull) withSubscriptionId:(NSString * _Nonnull)subscription request.additionalHeaders = headers; - NSString *appId = [OneSignalConfigManager getAppId]; + NSString *appId = OneSignalIdentifiers.currentAppId; request.path = [NSString stringWithFormat:@"apps/%@/subscriptions/%@/iams", appId, subscriptionId]; return request; } diff --git a/iOS_SDK/OneSignalSDK/OneSignalInAppMessagesTests/EarlyTriggerTrackingTests.swift b/iOS_SDK/OneSignalSDK/OneSignalInAppMessagesTests/EarlyTriggerTrackingTests.swift index 474e4d5a7..bedfe909e 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalInAppMessagesTests/EarlyTriggerTrackingTests.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalInAppMessagesTests/EarlyTriggerTrackingTests.swift @@ -53,7 +53,7 @@ final class EarlyTriggerTrackingTests: XCTestCase { OSMessagingController.removeInstance() // Set up basic configuration - OneSignalConfigManager.setAppId(testAppId) + OneSignalIdentifiers.currentAppId = testAppId OneSignalLog.setLogLevel(.LL_VERBOSE) } diff --git a/iOS_SDK/OneSignalSDK/OneSignalInAppMessagesTests/IAMIntegrationTests.swift b/iOS_SDK/OneSignalSDK/OneSignalInAppMessagesTests/IAMIntegrationTests.swift index fe968a899..cf1e824ec 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalInAppMessagesTests/IAMIntegrationTests.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalInAppMessagesTests/IAMIntegrationTests.swift @@ -55,7 +55,7 @@ final class IAMIntegrationTests: XCTestCase { /* Setup */ OneSignalCoreImpl.setSharedClient(MockOneSignalClient()) // App ID is set because there are guards against nil App ID - OneSignalConfigManager.setAppId("test-app-id") + OneSignalIdentifiers.currentAppId = "test-app-id" // 1. Pause IAMs OneSignalInAppMessages.__paused(true) @@ -82,7 +82,7 @@ final class IAMIntegrationTests: XCTestCase { OneSignalCoreImpl.setSharedClient(client) // 1. App ID is set because there are guards against nil App ID - OneSignalConfigManager.setAppId("test-app-id") + OneSignalIdentifiers.currentAppId = "test-app-id" // 2. Set up mock responses for the anonymous user, as the user needs an OSID MockUserRequests.setDefaultCreateAnonUserResponses(with: client) diff --git a/iOS_SDK/OneSignalSDK/OneSignalInAppMessagesTests/OSMessagingControllerUserStateTests.swift b/iOS_SDK/OneSignalSDK/OneSignalInAppMessagesTests/OSMessagingControllerUserStateTests.swift index e4ec5585d..8d7ada7cb 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalInAppMessagesTests/OSMessagingControllerUserStateTests.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalInAppMessagesTests/OSMessagingControllerUserStateTests.swift @@ -54,7 +54,7 @@ final class OSMessagingControllerUserStateTests: XCTestCase { OSMessagingController.removeInstance() // Set up basic configuration - OneSignalConfigManager.setAppId(testAppId) + OneSignalIdentifiers.currentAppId = testAppId OneSignalLog.setLogLevel(.LL_VERBOSE) } diff --git a/iOS_SDK/OneSignalSDK/OneSignalLiveActivities/Source/Requests/OSRequestLiveActivityClicked.swift b/iOS_SDK/OneSignalSDK/OneSignalLiveActivities/Source/Requests/OSRequestLiveActivityClicked.swift index d6bbb58e6..15a6c2c0a 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalLiveActivities/Source/Requests/OSRequestLiveActivityClicked.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalLiveActivities/Source/Requests/OSRequestLiveActivityClicked.swift @@ -26,6 +26,7 @@ */ import OneSignalCore +import OneSignalOSCore import OneSignalUser class OSRequestLiveActivityClicked: OneSignalRequest, OSLiveActivityRequest { @@ -39,7 +40,7 @@ class OSRequestLiveActivityClicked: OneSignalRequest, OSLiveActivityRequest { var shouldForgetWhenSuccessful: Bool = true func prepareForExecution() -> Bool { - guard let appId = OneSignalConfigManager.getAppId() else { + guard let appId = OneSignalIdentifiers.currentAppId else { OneSignalLog.onesignalLog(.LL_DEBUG, message: "Cannot generate the OSRequestLiveActivityClicked due to null app ID.") return false } diff --git a/iOS_SDK/OneSignalSDK/OneSignalLiveActivities/Source/Requests/OSRequestLiveActivityReceiveReceipts.swift b/iOS_SDK/OneSignalSDK/OneSignalLiveActivities/Source/Requests/OSRequestLiveActivityReceiveReceipts.swift index 6bae8f371..657e87c7d 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalLiveActivities/Source/Requests/OSRequestLiveActivityReceiveReceipts.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalLiveActivities/Source/Requests/OSRequestLiveActivityReceiveReceipts.swift @@ -26,6 +26,7 @@ */ import OneSignalCore +import OneSignalOSCore import OneSignalUser class OSRequestLiveActivityReceiveReceipts: OneSignalRequest, OSLiveActivityRequest { @@ -38,7 +39,7 @@ class OSRequestLiveActivityReceiveReceipts: OneSignalRequest, OSLiveActivityRequ var shouldForgetWhenSuccessful: Bool = true func prepareForExecution() -> Bool { - guard let appId = OneSignalConfigManager.getAppId() else { + guard let appId = OneSignalIdentifiers.currentAppId else { OneSignalLog.onesignalLog(.LL_DEBUG, message: "Cannot generate the OSRequestLiveActivityReceiveReceipts due to null app ID.") return false } diff --git a/iOS_SDK/OneSignalSDK/OneSignalLiveActivities/Source/Requests/OSRequestRemoveStartToken.swift b/iOS_SDK/OneSignalSDK/OneSignalLiveActivities/Source/Requests/OSRequestRemoveStartToken.swift index 1941cf43d..cf6fe9e0e 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalLiveActivities/Source/Requests/OSRequestRemoveStartToken.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalLiveActivities/Source/Requests/OSRequestRemoveStartToken.swift @@ -26,6 +26,7 @@ */ import OneSignalCore +import OneSignalOSCore import OneSignalUser class OSRequestRemoveStartToken: OneSignalRequest, OSLiveActivityRequest, OSLiveActivityStartTokenRequest { @@ -36,7 +37,7 @@ class OSRequestRemoveStartToken: OneSignalRequest, OSLiveActivityRequest, OSLive var shouldForgetWhenSuccessful: Bool = true func prepareForExecution() -> Bool { - guard let appId = OneSignalConfigManager.getAppId() else { + guard let appId = OneSignalIdentifiers.currentAppId else { OneSignalLog.onesignalLog(.LL_DEBUG, message: "Cannot generate the remove start token request due to null app ID.") return false } diff --git a/iOS_SDK/OneSignalSDK/OneSignalLiveActivities/Source/Requests/OSRequestRemoveUpdateToken.swift b/iOS_SDK/OneSignalSDK/OneSignalLiveActivities/Source/Requests/OSRequestRemoveUpdateToken.swift index 74ed764de..cfc2f71ce 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalLiveActivities/Source/Requests/OSRequestRemoveUpdateToken.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalLiveActivities/Source/Requests/OSRequestRemoveUpdateToken.swift @@ -26,6 +26,7 @@ */ import OneSignalCore +import OneSignalOSCore import OneSignalUser class OSRequestRemoveUpdateToken: OneSignalRequest, OSLiveActivityRequest, OSLiveActivityUpdateTokenRequest { @@ -36,7 +37,7 @@ class OSRequestRemoveUpdateToken: OneSignalRequest, OSLiveActivityRequest, OSLiv var shouldForgetWhenSuccessful: Bool = true func prepareForExecution() -> Bool { - guard let appId = OneSignalConfigManager.getAppId() else { + guard let appId = OneSignalIdentifiers.currentAppId else { OneSignalLog.onesignalLog(.LL_DEBUG, message: "Cannot generate the remove update token request due to null app ID.") return false } diff --git a/iOS_SDK/OneSignalSDK/OneSignalLiveActivities/Source/Requests/OSRequestSetStartToken.swift b/iOS_SDK/OneSignalSDK/OneSignalLiveActivities/Source/Requests/OSRequestSetStartToken.swift index 81469d3f4..a517fabd8 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalLiveActivities/Source/Requests/OSRequestSetStartToken.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalLiveActivities/Source/Requests/OSRequestSetStartToken.swift @@ -26,6 +26,7 @@ */ import OneSignalCore +import OneSignalOSCore import OneSignalUser class OSRequestSetStartToken: OneSignalRequest, OSLiveActivityRequest, OSLiveActivityStartTokenRequest { @@ -37,7 +38,7 @@ class OSRequestSetStartToken: OneSignalRequest, OSLiveActivityRequest, OSLiveAct var shouldForgetWhenSuccessful: Bool = false func prepareForExecution() -> Bool { - guard let appId = OneSignalConfigManager.getAppId() else { + guard let appId = OneSignalIdentifiers.currentAppId else { OneSignalLog.onesignalLog(.LL_DEBUG, message: "Cannot generate the set start token request due to null app ID.") return false } diff --git a/iOS_SDK/OneSignalSDK/OneSignalLiveActivities/Source/Requests/OSRequestSetUpdateToken.swift b/iOS_SDK/OneSignalSDK/OneSignalLiveActivities/Source/Requests/OSRequestSetUpdateToken.swift index 994a8cabf..38a0d3e12 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalLiveActivities/Source/Requests/OSRequestSetUpdateToken.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalLiveActivities/Source/Requests/OSRequestSetUpdateToken.swift @@ -26,6 +26,7 @@ */ import OneSignalCore +import OneSignalOSCore import OneSignalUser class OSRequestSetUpdateToken: OneSignalRequest, OSLiveActivityRequest, OSLiveActivityUpdateTokenRequest { @@ -37,7 +38,7 @@ class OSRequestSetUpdateToken: OneSignalRequest, OSLiveActivityRequest, OSLiveAc var shouldForgetWhenSuccessful: Bool = false func prepareForExecution() -> Bool { - guard let appId = OneSignalConfigManager.getAppId() else { + guard let appId = OneSignalIdentifiers.currentAppId else { OneSignalLog.onesignalLog(.LL_DEBUG, message: "Cannot generate the set update token request due to null app ID.") return false } diff --git a/iOS_SDK/OneSignalSDK/OneSignalLiveActivitiesTests/OSLiveActivitiesExecutorTests.swift b/iOS_SDK/OneSignalSDK/OneSignalLiveActivitiesTests/OSLiveActivitiesExecutorTests.swift index 5bc7fa84c..675f466c5 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalLiveActivitiesTests/OSLiveActivitiesExecutorTests.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalLiveActivitiesTests/OSLiveActivitiesExecutorTests.swift @@ -27,6 +27,7 @@ with services provided by OneSignal. import XCTest import OneSignalCore +import OneSignalOSCore import OneSignalUser import OneSignalCoreMocks import OneSignalUserMocks @@ -41,7 +42,7 @@ final class OSLiveActivitiesExecutorTests: XCTestCase { OneSignalCoreMocks.clearUserDefaults() OneSignalUserMocks.reset() // App ID is set because User Manager has guards against nil App ID - OneSignalConfigManager.setAppId("test-app-id") + OneSignalIdentifiers.currentAppId = "test-app-id" // Temp. logging to help debug during testing OneSignalLog.setLogLevel(.LL_VERBOSE) } diff --git a/iOS_SDK/OneSignalSDK/OneSignalLocation/OneSignalLocationManager.m b/iOS_SDK/OneSignalSDK/OneSignalLocation/OneSignalLocationManager.m index dae1d86ec..2bea4922d 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalLocation/OneSignalLocationManager.m +++ b/iOS_SDK/OneSignalSDK/OneSignalLocation/OneSignalLocationManager.m @@ -29,6 +29,7 @@ #import #import "OneSignalLocationManager.h" #import +#import #import "OSMacros.h" #import @@ -87,7 +88,7 @@ +(OneSignalLocationManager*) sharedInstance { } + (void)start { - if ([OneSignalConfigManager getAppId] != nil && [self isShared]) { + if (OneSignalIdentifiers.currentAppId != nil && [self isShared]) { [OneSignalLocationManager getLocation:false fallbackToSettings:false withCompletionHandler:nil]; } } diff --git a/iOS_SDK/OneSignalSDK/OneSignalNotifications/Categories/UIApplicationDelegate+OneSignalNotifications.m b/iOS_SDK/OneSignalSDK/OneSignalNotifications/Categories/UIApplicationDelegate+OneSignalNotifications.m index 563429203..f319b4896 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalNotifications/Categories/UIApplicationDelegate+OneSignalNotifications.m +++ b/iOS_SDK/OneSignalSDK/OneSignalNotifications/Categories/UIApplicationDelegate+OneSignalNotifications.m @@ -27,6 +27,7 @@ #import #import +#import #import "OneSignalNotifications.h" #import "UIApplicationDelegate+OneSignalNotifications.h" #import "OSNotification+Internal.h" @@ -131,7 +132,7 @@ - (void)oneSignalDidRegisterForRemoteNotifications:(UIApplication*)app deviceTok - (void)oneSignalDidFailRegisterForRemoteNotification:(UIApplication*)app error:(NSError*)err { [OneSignalNotificationsAppDelegate traceCall:@"oneSignalDidFailRegisterForRemoteNotification:error:"]; - if ([OneSignalConfigManager getAppId]) + if (OneSignalIdentifiers.currentAppId) [OSNotificationsManager processFailedRemoteNotificationsRegistration:err]; SwizzlingForwarder *forwarder = [[SwizzlingForwarder alloc] @@ -165,7 +166,7 @@ - (void) oneSignalReceiveRemoteNotification:(UIApplication*)application UserInfo BOOL startedBackgroundJob = false; - if ([OneSignalConfigManager getAppId]) { + if (OneSignalIdentifiers.currentAppId) { let appState = [UIApplication sharedApplication].applicationState; let isVisibleNotification = userInfo[@"aps"][@"alert"] != nil; diff --git a/iOS_SDK/OneSignalSDK/OneSignalNotifications/Categories/UNUserNotificationCenter+OneSignalNotifications.m b/iOS_SDK/OneSignalSDK/OneSignalNotifications/Categories/UNUserNotificationCenter+OneSignalNotifications.m index ede5b9ff4..24cca02dd 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalNotifications/Categories/UNUserNotificationCenter+OneSignalNotifications.m +++ b/iOS_SDK/OneSignalSDK/OneSignalNotifications/Categories/UNUserNotificationCenter+OneSignalNotifications.m @@ -33,6 +33,7 @@ #import "UIApplicationDelegate+OneSignalNotifications.h" #import "OSNotificationsManager.h" #import +#import #import "OSMacros.h" #import #pragma clang diagnostic push @@ -310,7 +311,7 @@ void finishProcessingNotification(UNNotification *notification, [OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"Notification display type: %lu", (unsigned long)displayType]]; - if ([OneSignalConfigManager getAppId]) + if (OneSignalIdentifiers.currentAppId) [OSNotificationsManager notificationReceived:notification.request.content.userInfo wasOpened:NO]; diff --git a/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.m b/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.m index f887dd9af..482b7fdcd 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.m +++ b/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.m @@ -612,7 +612,7 @@ + (void)notificationReceived:(NSDictionary*)messageDict wasOpened:(BOOL)opened { if ([OSPrivacyConsentController shouldLogMissingPrivacyConsentErrorWithMethodName:nil]) return; - if (![OneSignalConfigManager getAppId]) { + if (!OneSignalIdentifiers.currentAppId) { return; } @@ -774,7 +774,7 @@ + (void)submitNotificationOpened:(NSString*)messageId { //Only submit request if messageId not nil and: (lastMessage is nil or not equal to current one) if(messageId && (!lastMessageId || ![lastMessageId isEqualToString:messageId])) { [OneSignalCoreImpl.sharedClient executeRequest:[OSRequestSubmitNotificationOpened withUserId:OneSignalIdentifiers.subscriptionId - appId:[OneSignalConfigManager getAppId] + appId:OneSignalIdentifiers.currentAppId wasOpened:YES messageId:messageId withDeviceType:[NSNumber numberWithInt:DEVICE_TYPE_PUSH]] @@ -1035,7 +1035,7 @@ + (void)didReceiveNotificationResponse:(UNNotificationResponse *)response { + (void)processNotificationResponse:(UNNotificationResponse *)response { if ([OSPrivacyConsentController shouldLogMissingPrivacyConsentErrorWithMethodName:nil]) return; - if (![OneSignalConfigManager getAppId]) + if (!OneSignalIdentifiers.currentAppId) return; if ([@"com.apple.UNNotificationDismissActionIdentifier" isEqual:response.actionIdentifier]) return; diff --git a/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSOperationRepo.swift b/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSOperationRepo.swift index 8d85d17b0..95dc07ec8 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSOperationRepo.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSOperationRepo.swift @@ -54,7 +54,7 @@ public class OSOperationRepo: NSObject { Likely call init on this from oneSignal but exeuctors can come from diff modules. */ public func start() { - guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: nil) else { + guard !OneSignalConfig.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: nil) else { return } guard !hasCalledStart else { @@ -90,7 +90,7 @@ public class OSOperationRepo: NSObject { Add and start an executor. */ public func addExecutor(_ executor: OSOperationExecutor) { - guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: nil) else { + guard !OneSignalConfig.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: nil) else { return } start() @@ -108,7 +108,7 @@ public class OSOperationRepo: NSObject { This can happen when session data and purchase data use the model / store / listener infrastructure. */ public func enqueueDelta(_ delta: OSDelta, flush: Bool = false) { - guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: nil) else { + guard !OneSignalConfig.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: nil) else { return } start() @@ -137,7 +137,7 @@ public class OSOperationRepo: NSObject { return } - guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: nil) else { + guard !OneSignalConfig.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: nil) else { return } diff --git a/iOS_SDK/OneSignalSDK/OneSignalCore/Source/OneSignalConfigManager.m b/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OneSignalConfig.swift similarity index 52% rename from iOS_SDK/OneSignalSDK/OneSignalCore/Source/OneSignalConfigManager.m rename to iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OneSignalConfig.swift index 41060e347..9af2a3080 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalCore/Source/OneSignalConfigManager.m +++ b/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OneSignalConfig.swift @@ -1,7 +1,7 @@ /* Modified MIT License - Copyright 2022 OneSignal + Copyright 2026 OneSignal Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -25,32 +25,27 @@ of this software and associated documentation files (the "Software"), to deal THE SOFTWARE. */ -#import "OneSignalConfigManager.h" -#import "OSPrivacyConsentController.h" -#import "OneSignalLog.h" - -@implementation OneSignalConfigManager - -static NSString *_appId; -+ (void)setAppId:(NSString *)appId { - _appId = appId; -} -+ (NSString *_Nullable)getAppId { - return _appId; -} - -+ (BOOL)shouldAwaitAppIdAndLogMissingPrivacyConsentForMethod:(NSString *)methodName { - BOOL shouldAwait = false; - if (!_appId) { - if (methodName) { - [OneSignalLog onesignalLog:ONE_S_LL_WARN message:[NSString stringWithFormat:@"Your application has called %@ before app ID has been set. Please call `initialize:appId withLaunchOptions:launchOptions` in order to set the app ID", methodName]]; +import Foundation +import OneSignalCore + +/// SDK-level configuration / readiness predicates. Replaces +@objc(OneSignalConfig) +public final class OneSignalConfig: NSObject { + + /// Returns true when the SDK shouldn't perform an operation yet because either: + /// * `app_id` hasn't been set via `OneSignal.initialize`, or + /// * the host app hasn't granted privacy consent (per `OSPrivacyConsentController`). + @objc public static func shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod methodName: String?) -> Bool { + var shouldAwait = false + if OneSignalIdentifiers.currentAppId == nil { + if let methodName { + OneSignalLog.onesignalLog(.LL_WARN, message: "Your application has called \(methodName) before app ID has been set. Please call `initialize:appId withLaunchOptions:launchOptions` in order to set the app ID") + } + shouldAwait = true } - shouldAwait = true; - } - if ([OSPrivacyConsentController shouldLogMissingPrivacyConsentErrorWithMethodName:methodName]) { - shouldAwait = true; + if OSPrivacyConsentController.shouldLogMissingPrivacyConsentError(withMethodName: methodName) { + shouldAwait = true + } + return shouldAwait } - return shouldAwait; } - -@end diff --git a/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OneSignalIdentifiers.swift b/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OneSignalIdentifiers.swift index 54fb464ef..129a274ab 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OneSignalIdentifiers.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OneSignalIdentifiers.swift @@ -36,6 +36,17 @@ import OneSignalCore @objc(OneSignalIdentifiers) public final class OneSignalIdentifiers: NSObject { + private static let lock = NSLock() + private static var _currentAppId: String? + + /// The current in-memory `app_id`, set by `OneSignal.initialize`. + /// nil before `initialize` has been called (or in a process like the NSE that + /// never calls `initialize` — use `storedAppId` there). + @objc public static var currentAppId: String? { + get { lock.withLock { _currentAppId } } + set { lock.withLock { _currentAppId = newValue } } + } + /// Last-known persisted `app_id` from shared UserDefaults. Returns nil if absent. @objc public static var storedAppId: String? { return OneSignalUserDefaults.initShared().getSavedString(forKey: OSUD_APP_ID, defaultValue: nil) diff --git a/iOS_SDK/OneSignalSDK/OneSignalOutcomes/Source/OutcomeEvents/OneSignalOutcomeEventsController.m b/iOS_SDK/OneSignalSDK/OneSignalOutcomes/Source/OutcomeEvents/OneSignalOutcomeEventsController.m index c8d849870..d792ae8cc 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalOutcomes/Source/OutcomeEvents/OneSignalOutcomeEventsController.m +++ b/iOS_SDK/OneSignalSDK/OneSignalOutcomes/Source/OutcomeEvents/OneSignalOutcomeEventsController.m @@ -28,6 +28,7 @@ of this software and associated documentation files (the "Software"), to deal #import #import "OneSignalOutcomeEventsController.h" #import +#import #import "OSOutcomeEvent.h" #import "OSCachedUniqueOutcome.h" #import "OSSessionManager.h" @@ -339,7 +340,7 @@ - (void)addOutcome:(NSString * _Nonnull)name { return; } - [self sendOutcomeEvent:name appId:[OneSignalConfigManager getAppId] deviceType:[NSNumber numberWithInt:DEVICE_TYPE_PUSH] successBlock:nil]; + [self sendOutcomeEvent:name appId:OneSignalIdentifiers.currentAppId deviceType:[NSNumber numberWithInt:DEVICE_TYPE_PUSH] successBlock:nil]; } - (void)addOutcomeWithValue:(NSString * _Nonnull)name value:(NSNumber * _Nonnull)value { @@ -347,7 +348,7 @@ - (void)addOutcomeWithValue:(NSString * _Nonnull)name value:(NSNumber * _Nonnull return; } - [self sendOutcomeEventWithValue:name value:value appId:[OneSignalConfigManager getAppId] deviceType:[NSNumber numberWithInt:DEVICE_TYPE_PUSH] successBlock:nil]; + [self sendOutcomeEventWithValue:name value:value appId:OneSignalIdentifiers.currentAppId deviceType:[NSNumber numberWithInt:DEVICE_TYPE_PUSH] successBlock:nil]; } - (void)addUniqueOutcome:(NSString * _Nonnull)name { @@ -355,7 +356,7 @@ - (void)addUniqueOutcome:(NSString * _Nonnull)name { return; } - [self sendUniqueOutcomeEvent:name appId:[OneSignalConfigManager getAppId] deviceType:[NSNumber numberWithInt:DEVICE_TYPE_PUSH] successBlock:nil]; + [self sendUniqueOutcomeEvent:name appId:OneSignalIdentifiers.currentAppId deviceType:[NSNumber numberWithInt:DEVICE_TYPE_PUSH] successBlock:nil]; } - (BOOL)isValidOutcomeEntry:(NSString * _Nonnull)name { diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift index 78977e737..efc02663f 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift @@ -137,7 +137,7 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager { private var jwtExpiredHandler: OSJwtExpiredHandler? var user: OSUserInternal { - guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: nil) else { + guard !OneSignalConfig.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: nil) else { return _mockUser } start() @@ -203,7 +203,7 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager { @objc public func start() { - guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: nil) else { + guard !OneSignalConfig.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: nil) else { return } @@ -288,7 +288,7 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager { @objc public func login(externalId: String, token: String?) { - guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: nil) else { + guard !OneSignalConfig.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: nil) else { return } start() @@ -336,7 +336,7 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager { } private func createNewUser(externalId: String?, token: String?) -> OSUserInternal { - guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: nil) else { + guard !OneSignalConfig.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: nil) else { return _mockUser } @@ -369,7 +369,7 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager { 2. This externalId doesn't exist on any users. We successfully identify the user, but we still create a new SDK user and fetch to update it. */ private func identifyUser(externalId: String, currentUser: OSUserInternal) { - guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: nil) else { + guard !OneSignalConfig.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: nil) else { return } @@ -421,7 +421,7 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager { */ @objc public func logout() { - guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "logout") else { + guard !OneSignalConfig.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "logout") else { return } guard user.identityModel.externalId != nil else { @@ -443,7 +443,7 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager { } private func createUserIfNil() { - guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: nil) else { + guard !OneSignalConfig.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: nil) else { return } _ = self.user @@ -530,7 +530,7 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager { @objc public func setLocation(latitude: Float, longitude: Float) { - guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "setLocation") else { + guard !OneSignalConfig.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "setLocation") else { return } guard let user = _user else { @@ -542,7 +542,7 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager { @objc public func sendPurchases(_ purchases: [[String: AnyObject]]) { - guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "sendPurchases") else { + guard !OneSignalConfig.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "sendPurchases") else { return } updatePropertiesDeltas(property: .purchases, value: purchases) @@ -567,7 +567,7 @@ extension OneSignalUserManagerImpl { @objc public func startNewSession() { OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OneSignalUserManagerImpl starting new session") - guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "_startNewSession") else { + guard !OneSignalConfig.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "_startNewSession") else { return } start() @@ -592,7 +592,7 @@ extension OneSignalUserManagerImpl { /// - Parameter property:Expected inputs are `.session_time"`, `.session_count"`, and `.purchases"`. /// May be `.timezone_id` or others if the SDK is sending an update for a legacy player. func updatePropertiesDeltas(property: OSPropertiesSupportedProperty, value: Any, flush: Bool = false) { - guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "updatePropertiesDeltas") else { + guard !OneSignalConfig.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "updatePropertiesDeltas") else { return } @@ -617,7 +617,7 @@ extension OneSignalUserManagerImpl { /// Time processors forward the session time to this method. @objc public func sendSessionTime(_ sessionTime: NSNumber) { - guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "sendSessionTime") else { + guard !OneSignalConfig.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "sendSessionTime") else { return } updatePropertiesDeltas(property: .session_time, value: sessionTime.intValue) @@ -649,14 +649,14 @@ extension OneSignalUserManagerImpl: OSUser { } public var externalId: String? { - guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "externalId") else { + guard !OneSignalConfig.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "externalId") else { return nil } return _user?.identityModel.externalId } public var onesignalId: String? { - guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "onesignalId") else { + guard !OneSignalConfig.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "onesignalId") else { return nil } return _user?.identityModel.onesignalId @@ -672,70 +672,70 @@ extension OneSignalUserManagerImpl: OSUser { } public func addAlias(label: String, id: String) { - guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "addAlias") else { + guard !OneSignalConfig.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "addAlias") else { return } user.addAliases([label: id]) } public func addAliases(_ aliases: [String: String]) { - guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "addAliases") else { + guard !OneSignalConfig.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "addAliases") else { return } user.addAliases(aliases) } public func removeAlias(_ label: String) { - guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "removeAlias") else { + guard !OneSignalConfig.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "removeAlias") else { return } user.removeAliases([label]) } public func removeAliases(_ labels: [String]) { - guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "removeAliases") else { + guard !OneSignalConfig.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "removeAliases") else { return } user.removeAliases(labels) } public func addTag(key: String, value: String) { - guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "addTag") else { + guard !OneSignalConfig.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "addTag") else { return } user.addTags([key: value]) } public func addTags(_ tags: [String: String]) { - guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "addTags") else { + guard !OneSignalConfig.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "addTags") else { return } user.addTags(tags) } public func removeTag(_ tag: String) { - guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "removeTag") else { + guard !OneSignalConfig.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "removeTag") else { return } user.removeTags([tag]) } public func removeTags(_ tags: [String]) { - guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "removeTags") else { + guard !OneSignalConfig.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "removeTags") else { return } user.removeTags(tags) } public func getTags() -> [String: String] { - guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "getTags") else { + guard !OneSignalConfig.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "getTags") else { return [:] } return user.propertiesModel.tags } public func addEmail(_ email: String) { - guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "addEmail") else { + guard !OneSignalConfig.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "addEmail") else { return } // Check if is valid email? @@ -758,7 +758,7 @@ extension OneSignalUserManagerImpl: OSUser { Error handling needs to be implemented in the future. */ public func removeEmail(_ email: String) { - guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "removeEmail") else { + guard !OneSignalConfig.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "removeEmail") else { return } // Check if is valid email? @@ -767,7 +767,7 @@ extension OneSignalUserManagerImpl: OSUser { } public func addSms(_ number: String) { - guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "addSmsNumber") else { + guard !OneSignalConfig.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "addSmsNumber") else { return } // Check if is valid SMS? @@ -790,7 +790,7 @@ extension OneSignalUserManagerImpl: OSUser { Error handling needs to be implemented in the future. */ public func removeSms(_ number: String) { - guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "removeSmsNumber") else { + guard !OneSignalConfig.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "removeSmsNumber") else { return } // Check if is valid SMS? @@ -799,7 +799,7 @@ extension OneSignalUserManagerImpl: OSUser { } public func setLanguage(_ language: String) { - guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "setLanguage") else { + guard !OneSignalConfig.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "setLanguage") else { return } @@ -812,7 +812,7 @@ extension OneSignalUserManagerImpl: OSUser { } public func trackEvent(name: String, properties: [String: Any]?) { - guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "trackEvent") else { + guard !OneSignalConfig.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "trackEvent") else { return } @@ -869,21 +869,21 @@ extension OneSignalUserManagerImpl { } public var id: String? { - guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "pushSubscription.id") else { + guard !OneSignalConfig.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "pushSubscription.id") else { return nil } return pushSubscriptionModelStore.getModel(key: OS_PUSH_SUBSCRIPTION_MODEL_KEY)?.subscriptionId } public var token: String? { - guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "pushSubscription.token") else { + guard !OneSignalConfig.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "pushSubscription.token") else { return nil } return pushSubscriptionModelStore.getModel(key: OS_PUSH_SUBSCRIPTION_MODEL_KEY)?.address } public var optedIn: Bool { - guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "pushSubscription.optedIn") else { + guard !OneSignalConfig.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "pushSubscription.optedIn") else { return false } return pushSubscriptionModelStore.getModel(key: OS_PUSH_SUBSCRIPTION_MODEL_KEY)?.optedIn ?? false @@ -893,7 +893,7 @@ extension OneSignalUserManagerImpl { Enable the push subscription, and prompts if needed. `optedIn` can still be `false` after `optIn()` is called if permission is not granted. */ public func optIn() { - guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "pushSubscription.optIn") else { + guard !OneSignalConfig.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "pushSubscription.optIn") else { return } pushSubscriptionModelStore.getModel(key: OS_PUSH_SUBSCRIPTION_MODEL_KEY)?._isDisabled = false @@ -901,7 +901,7 @@ extension OneSignalUserManagerImpl { } public func optOut() { - guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "pushSubscription.optOut") else { + guard !OneSignalConfig.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "pushSubscription.optOut") else { return } pushSubscriptionModelStore.getModel(key: OS_PUSH_SUBSCRIPTION_MODEL_KEY)?._isDisabled = true @@ -914,14 +914,14 @@ extension OneSignalUserManagerImpl: OneSignalNotificationsDelegate { // Once the UserManager is started in `init`, it calls these to set the state of the pushSubscriptionModel public func setNotificationTypes(_ notificationTypes: Int32) { - guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: nil) else { + guard !OneSignalConfig.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: nil) else { return } user.pushSubscriptionModel.notificationTypes = Int(notificationTypes) } public func setPushToken(_ pushToken: String) { - guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: nil) else { + guard !OneSignalConfig.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: nil) else { return } user.pushSubscriptionModel.address = pushToken diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Requests/OSRequestAddAliases.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Requests/OSRequestAddAliases.swift index c52a84e20..a4ad372a0 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Requests/OSRequestAddAliases.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Requests/OSRequestAddAliases.swift @@ -42,7 +42,7 @@ class OSRequestAddAliases: OneSignalRequest, OSUserRequest { func prepareForExecution(newRecordsState: OSNewRecordsState) -> Bool { if let onesignalId = identityModel.onesignalId, newRecordsState.canAccess(onesignalId), - let appId = OneSignalConfigManager.getAppId() + let appId = OneSignalIdentifiers.currentAppId { self.addJWTHeader(identityModel: identityModel) self.path = "apps/\(appId)/users/by/\(OS_ONESIGNAL_ID)/\(onesignalId)/identity" diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Requests/OSRequestCreateSubscription.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Requests/OSRequestCreateSubscription.swift index 51b383d6e..e95281e5e 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Requests/OSRequestCreateSubscription.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Requests/OSRequestCreateSubscription.swift @@ -47,7 +47,7 @@ class OSRequestCreateSubscription: OneSignalRequest, OSUserRequest { func prepareForExecution(newRecordsState: OSNewRecordsState) -> Bool { if let onesignalId = identityModel.onesignalId, newRecordsState.canAccess(onesignalId), - let appId = OneSignalConfigManager.getAppId() + let appId = OneSignalIdentifiers.currentAppId { self.addJWTHeader(identityModel: identityModel) self.path = "apps/\(appId)/users/by/\(OS_ONESIGNAL_ID)/\(onesignalId)/subscriptions" diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Requests/OSRequestCreateUser.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Requests/OSRequestCreateUser.swift index ef4e4a5e3..a74514f11 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Requests/OSRequestCreateUser.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Requests/OSRequestCreateUser.swift @@ -47,7 +47,7 @@ class OSRequestCreateUser: OneSignalRequest, OSUserRequest { /// Checks if the subscription ID can be accessed, if a subscription is being included in the request func prepareForExecution(newRecordsState: OSNewRecordsState) -> Bool { - guard let appId = OneSignalConfigManager.getAppId() else { + guard let appId = OneSignalIdentifiers.currentAppId else { OneSignalLog.onesignalLog(.LL_ERROR, message: "Cannot generate the create user request due to null app ID.") return false } diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Requests/OSRequestCustomEvents.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Requests/OSRequestCustomEvents.swift index 6dbe78abb..83ec1e565 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Requests/OSRequestCustomEvents.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Requests/OSRequestCustomEvents.swift @@ -40,7 +40,7 @@ class OSRequestCustomEvents: OneSignalRequest, OSUserRequest { func prepareForExecution(newRecordsState: OSNewRecordsState) -> Bool { if let onesignalId = identityModel.onesignalId, newRecordsState.canAccess(onesignalId), - let appId = OneSignalConfigManager.getAppId() + let appId = OneSignalIdentifiers.currentAppId { _ = self.addPushSubscriptionIdToAdditionalHeaders() self.path = "apps/\(appId)/custom_events" diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Requests/OSRequestDeleteSubscription.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Requests/OSRequestDeleteSubscription.swift index 35c36c2ad..43cd37e3b 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Requests/OSRequestDeleteSubscription.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Requests/OSRequestDeleteSubscription.swift @@ -46,7 +46,7 @@ class OSRequestDeleteSubscription: OneSignalRequest, OSUserRequest { func prepareForExecution(newRecordsState: OSNewRecordsState) -> Bool { if let subscriptionId = subscriptionModel.subscriptionId, newRecordsState.canAccess(subscriptionId), - let appId = OneSignalConfigManager.getAppId() + let appId = OneSignalIdentifiers.currentAppId { self.path = "apps/\(appId)/subscriptions/\(subscriptionId)" return true diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Requests/OSRequestFetchIdentityBySubscription.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Requests/OSRequestFetchIdentityBySubscription.swift index e26c7855d..207209f3e 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Requests/OSRequestFetchIdentityBySubscription.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Requests/OSRequestFetchIdentityBySubscription.swift @@ -41,7 +41,7 @@ class OSRequestFetchIdentityBySubscription: OneSignalRequest, OSUserRequest { func prepareForExecution(newRecordsState: OSNewRecordsState) -> Bool { // newRecordsState is unused for this request - guard let appId = OneSignalConfigManager.getAppId() else { + guard let appId = OneSignalIdentifiers.currentAppId else { OneSignalLog.onesignalLog(.LL_DEBUG, message: "Cannot generate the FetchIdentityBySubscription request due to null app ID.") return false } diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Requests/OSRequestFetchUser.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Requests/OSRequestFetchUser.swift index 2e03e0c3e..8bf9b2973 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Requests/OSRequestFetchUser.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Requests/OSRequestFetchUser.swift @@ -45,7 +45,7 @@ class OSRequestFetchUser: OneSignalRequest, OSUserRequest { let onNewSession: Bool func prepareForExecution(newRecordsState: OSNewRecordsState) -> Bool { - guard let appId = OneSignalConfigManager.getAppId(), + guard let appId = OneSignalIdentifiers.currentAppId, newRecordsState.canAccess(aliasId) else { OneSignalLog.onesignalLog(.LL_DEBUG, message: "Cannot generate the fetch user request for \(aliasLabel): \(aliasId) yet.") diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Requests/OSRequestIdentifyUser.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Requests/OSRequestIdentifyUser.swift index b63c275a2..880b2e405 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Requests/OSRequestIdentifyUser.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Requests/OSRequestIdentifyUser.swift @@ -51,7 +51,7 @@ class OSRequestIdentifyUser: OneSignalRequest, OSUserRequest { func prepareForExecution(newRecordsState: OSNewRecordsState) -> Bool { if let onesignalId = identityModelToIdentify.onesignalId, newRecordsState.canAccess(onesignalId), - let appId = OneSignalConfigManager.getAppId() + let appId = OneSignalIdentifiers.currentAppId { self.addJWTHeader(identityModel: identityModelToIdentify) self.path = "apps/\(appId)/users/by/\(OS_ONESIGNAL_ID)/\(onesignalId)/identity" diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Requests/OSRequestRemoveAlias.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Requests/OSRequestRemoveAlias.swift index adf98e568..207cebd5a 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Requests/OSRequestRemoveAlias.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Requests/OSRequestRemoveAlias.swift @@ -41,7 +41,7 @@ class OSRequestRemoveAlias: OneSignalRequest, OSUserRequest { func prepareForExecution(newRecordsState: OSNewRecordsState) -> Bool { if let onesignalId = identityModel.onesignalId, newRecordsState.canAccess(onesignalId), - let appId = OneSignalConfigManager.getAppId() + let appId = OneSignalIdentifiers.currentAppId { self.addJWTHeader(identityModel: identityModel) self.path = "apps/\(appId)/users/by/\(OS_ONESIGNAL_ID)/\(onesignalId)/identity/\(labelToRemove)" diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Requests/OSRequestUpdateProperties.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Requests/OSRequestUpdateProperties.swift index b46ff3894..aed93ee04 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Requests/OSRequestUpdateProperties.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Requests/OSRequestUpdateProperties.swift @@ -42,7 +42,7 @@ class OSRequestUpdateProperties: OneSignalRequest, OSUserRequest { func prepareForExecution(newRecordsState: OSNewRecordsState) -> Bool { if let onesignalId = identityModel.onesignalId, newRecordsState.canAccess(onesignalId), - let appId = OneSignalConfigManager.getAppId() + let appId = OneSignalIdentifiers.currentAppId { _ = self.addPushSubscriptionIdToAdditionalHeaders() self.addJWTHeader(identityModel: identityModel) diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Requests/OSRequestUpdateSubscription.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Requests/OSRequestUpdateSubscription.swift index 39fba8c5c..9edba5375 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Requests/OSRequestUpdateSubscription.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/Requests/OSRequestUpdateSubscription.swift @@ -44,7 +44,7 @@ class OSRequestUpdateSubscription: OneSignalRequest, OSUserRequest { func prepareForExecution(newRecordsState: OSNewRecordsState) -> Bool { if let subscriptionId = subscriptionModel.subscriptionId, newRecordsState.canAccess(subscriptionId), - let appId = OneSignalConfigManager.getAppId() + let appId = OneSignalIdentifiers.currentAppId { self.path = "apps/\(appId)/subscriptions/\(subscriptionId)" return true diff --git a/iOS_SDK/OneSignalSDK/OneSignalUserTests/CustomEventsIntegrationTests.swift b/iOS_SDK/OneSignalSDK/OneSignalUserTests/CustomEventsIntegrationTests.swift index 043519c8a..be80f3310 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUserTests/CustomEventsIntegrationTests.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUserTests/CustomEventsIntegrationTests.swift @@ -38,7 +38,7 @@ final class CustomEventsIntegrationTests: XCTestCase { override func setUpWithError() throws { OneSignalCoreMocks.clearUserDefaults() OneSignalUserMocks.reset() - OneSignalConfigManager.setAppId("test-app-id") + OneSignalIdentifiers.currentAppId = "test-app-id" OneSignalLog.setLogLevel(.LL_VERBOSE) } diff --git a/iOS_SDK/OneSignalSDK/OneSignalUserTests/Executors/OSCustomEventsExecutorTests.swift b/iOS_SDK/OneSignalSDK/OneSignalUserTests/Executors/OSCustomEventsExecutorTests.swift index d61da089a..8f4154fc2 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUserTests/Executors/OSCustomEventsExecutorTests.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUserTests/Executors/OSCustomEventsExecutorTests.swift @@ -62,7 +62,7 @@ final class OSCustomEventsExecutorTests: XCTestCase { override func setUpWithError() throws { OneSignalCoreMocks.clearUserDefaults() OneSignalUserMocks.reset() - OneSignalConfigManager.setAppId("test-app-id") + OneSignalIdentifiers.currentAppId = "test-app-id" OneSignalLog.setLogLevel(.LL_VERBOSE) } diff --git a/iOS_SDK/OneSignalSDK/OneSignalUserTests/Executors/UserExecutorTests.swift b/iOS_SDK/OneSignalSDK/OneSignalUserTests/Executors/UserExecutorTests.swift index aee71dc02..f52163427 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUserTests/Executors/UserExecutorTests.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUserTests/Executors/UserExecutorTests.swift @@ -58,7 +58,7 @@ final class UserExecutorTests: XCTestCase { OneSignalCoreMocks.clearUserDefaults() OneSignalUserMocks.reset() // App ID is set because requests have guards against null App ID - OneSignalConfigManager.setAppId("test-app-id") + OneSignalIdentifiers.currentAppId = "test-app-id" // Temp. logging to help debug during testing OneSignalLog.setLogLevel(.LL_VERBOSE) } diff --git a/iOS_SDK/OneSignalSDK/OneSignalUserTests/OneSignalUserObjcTests.m b/iOS_SDK/OneSignalSDK/OneSignalUserTests/OneSignalUserObjcTests.m index fb26fd6b6..9348f639e 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUserTests/OneSignalUserObjcTests.m +++ b/iOS_SDK/OneSignalSDK/OneSignalUserTests/OneSignalUserObjcTests.m @@ -17,7 +17,7 @@ - (void)setUp { [OneSignalCoreMocks clearUserDefaults]; [OneSignalUserMocks reset]; // App ID is set because User Manager has guards against nil App ID - [OneSignalConfigManager setAppId:@"test-app-id"]; + [OneSignalIdentifiers setCurrentAppId:@"test-app-id"]; // Temp. logging to help debug during testing [OneSignalLog setLogLevel:ONE_S_LL_VERBOSE]; } diff --git a/iOS_SDK/OneSignalSDK/OneSignalUserTests/OneSignalUserTests.swift b/iOS_SDK/OneSignalSDK/OneSignalUserTests/OneSignalUserTests.swift index 3e292deae..c8e65f7b2 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUserTests/OneSignalUserTests.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUserTests/OneSignalUserTests.swift @@ -41,7 +41,7 @@ final class OneSignalUserTests: XCTestCase { OneSignalCoreMocks.clearUserDefaults() OneSignalUserMocks.reset() // App ID is set because User Manager has guards against nil App ID - OneSignalConfigManager.setAppId("test-app-id") + OneSignalIdentifiers.currentAppId = "test-app-id" // Temp. logging to help debug during testing OneSignalLog.setLogLevel(.LL_VERBOSE) } diff --git a/iOS_SDK/OneSignalSDK/OneSignalUserTests/SwitchUserIntegrationTests.swift b/iOS_SDK/OneSignalSDK/OneSignalUserTests/SwitchUserIntegrationTests.swift index 95859d323..b9ae4f6a4 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUserTests/SwitchUserIntegrationTests.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUserTests/SwitchUserIntegrationTests.swift @@ -13,7 +13,7 @@ final class SwitchUserIntegrationTests: XCTestCase { OneSignalCoreMocks.clearUserDefaults() OneSignalUserMocks.reset() // App ID is set because User Manager has guards against nil App ID - OneSignalConfigManager.setAppId("test-app-id") + OneSignalIdentifiers.currentAppId = "test-app-id" // Temp. logging to help debug during testing OneSignalLog.setLogLevel(.LL_VERBOSE) } diff --git a/iOS_SDK/OneSignalSDK/OneSignalUserTests/UserConcurrencyTests.swift b/iOS_SDK/OneSignalSDK/OneSignalUserTests/UserConcurrencyTests.swift index 5d5252a2d..106d4cfa6 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUserTests/UserConcurrencyTests.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUserTests/UserConcurrencyTests.swift @@ -41,7 +41,7 @@ final class UserConcurrencyTests: XCTestCase { OneSignalCoreMocks.clearUserDefaults() OneSignalUserMocks.reset() // App ID is set because User Manager has guards against nil App ID - OneSignalConfigManager.setAppId("test-app-id") + OneSignalIdentifiers.currentAppId = "test-app-id" // Temp. logging to help debug during testing OneSignalLog.setLogLevel(.LL_VERBOSE) } diff --git a/iOS_SDK/OneSignalSDK/Source/OneSignal.m b/iOS_SDK/OneSignalSDK/Source/OneSignal.m index fd8a3446b..a4e5bd653 100755 --- a/iOS_SDK/OneSignalSDK/Source/OneSignal.m +++ b/iOS_SDK/OneSignalSDK/Source/OneSignal.m @@ -136,7 +136,7 @@ + (OneSignalReceiveReceiptsController*)receiveReceiptsController { //TODO: This is related to unit tests and will change with um tests + (void)clearStatics { - [OneSignalConfigManager setAppId:nil]; + [OneSignalIdentifiers setCurrentAppId:nil]; launchOptions = false; appSettings = nil; initDone = false; @@ -162,7 +162,7 @@ + (void)clearStatics { + (void)login:(NSString * _Nonnull)externalId { // return if no app_id / the user has not granted privacy permissions - if ([OneSignalConfigManager shouldAwaitAppIdAndLogMissingPrivacyConsentForMethod:@"login"]) { + if ([OneSignalConfig shouldAwaitAppIdAndLogMissingPrivacyConsentForMethod:@"login"]) { return; } [OneSignalUserManagerImpl.sharedInstance loginWithExternalId:externalId token:nil]; @@ -172,7 +172,7 @@ + (void)login:(NSString * _Nonnull)externalId { + (void)login:(NSString * _Nonnull)externalId withToken:(NSString * _Nullable)token { // TODO: Need to await download iOS params // return if no app_id / the user has not granted privacy permissions - if ([OneSignalConfigManager shouldAwaitAppIdAndLogMissingPrivacyConsentForMethod:@"login"]) { + if ([OneSignalConfig shouldAwaitAppIdAndLogMissingPrivacyConsentForMethod:@"login"]) { return; } [OneSignalUserManagerImpl.sharedInstance loginWithExternalId:externalId token:token]; @@ -250,21 +250,21 @@ + (void)setAppId:(nullable NSString*)newAppId { NSString* cachedAppId = OneSignalIdentifiers.storedAppId; if (cachedAppId) { [OneSignalLog onesignalLog:ONE_S_LL_INFO message:[NSString stringWithFormat:@"Initializing OneSignal with cached appId: '%@'.", cachedAppId]]; - [OneSignalConfigManager setAppId:cachedAppId]; + [OneSignalIdentifiers setCurrentAppId:cachedAppId]; } else { [OneSignalLog onesignalLog:ONE_S_LL_INFO message:@"Waiting for setAppId(appId) with a valid appId to complete OneSignal init!"]; return; } - } else if ([OneSignalConfigManager getAppId] && ![newAppId isEqualToString:[OneSignalConfigManager getAppId]]) { + } else if (OneSignalIdentifiers.currentAppId && ![newAppId isEqualToString:OneSignalIdentifiers.currentAppId]) { // Pre-check on app id to make sure init of SDK is performed properly // Usually when the app id is changed during runtime so that SDK is reinitialized properly initDone = false; - [OneSignalConfigManager setAppId:newAppId]; + [OneSignalIdentifiers setCurrentAppId:newAppId]; } else { - [OneSignalConfigManager setAppId:newAppId]; + [OneSignalIdentifiers setCurrentAppId:newAppId]; } - [self handleAppIdChange:[OneSignalConfigManager getAppId]]; + [self handleAppIdChange:OneSignalIdentifiers.currentAppId]; } + (BOOL)isValidAppId:(NSString*)appId { @@ -446,16 +446,16 @@ + (void)startLiveActivitiesManager { + (void)delayInitializationForPrivacyConsent { [OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"Delayed initialization of the OneSignal SDK until the user provides privacy consent using the setPrivacyConsent() method"]; delayedInitializationForPrivacyConsent = true; - _delayedInitParameters = [[DelayedConsentInitializationParameters alloc] initWithLaunchOptions:launchOptions withAppId:[OneSignalConfigManager getAppId]]; + _delayedInitParameters = [[DelayedConsentInitializationParameters alloc] initWithLaunchOptions:launchOptions withAppId:OneSignalIdentifiers.currentAppId]; // Init was not successful, set appId back to nil - [OneSignalConfigManager setAppId:nil]; + [OneSignalIdentifiers setCurrentAppId:nil]; } /* Called after setAppId and setLaunchOptions, depending on which one is called last (order does not matter) */ + (void)init { - [OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"launchOptions is set and appId of %@ is set, initializing OneSignal...", [OneSignalConfigManager getAppId]]]; + [OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"launchOptions is set and appId of %@ is set, initializing OneSignal...", OneSignalIdentifiers.currentAppId]]; // TODO: We moved this check to the top of this method, we should test this. if (initDone) { @@ -470,8 +470,8 @@ + (void)init { // Wrapper SDK's call init twice and pass null as the appId on the first call // the app ID is required to download parameters, so do not download params until the appID is provided - if (!_didCallDownloadParameters && [OneSignalConfigManager getAppId] && [OneSignalConfigManager getAppId] != (id)[NSNull null]) - [self downloadIOSParamsWithAppId:[OneSignalConfigManager getAppId]]; + if (!_didCallDownloadParameters && OneSignalIdentifiers.currentAppId && OneSignalIdentifiers.currentAppId != (id)[NSNull null]) + [self downloadIOSParamsWithAppId:OneSignalIdentifiers.currentAppId]; // using classes as delegates is not best practice. We should consider using a shared instance of a class instead [OSSessionManager sharedSessionManager].delegate = (id)self; @@ -484,7 +484,7 @@ + (void)init { // Now really initializing the SDK! // Invalid app ids reaching here will cause failure - if (![self isValidAppId:[OneSignalConfigManager getAppId]]) + if (![self isValidAppId:OneSignalIdentifiers.currentAppId]) return; // TODO: Consider the implications of `registerUserInternal` previously running on the main_queue @@ -694,7 +694,7 @@ + (void)sendSessionEndOutcomes:(NSNumber*)totalTimeActive params:(OSFocusCallPar } [OSOutcomes.sharedController sendSessionEndOutcomes:totalTimeActive - appId:[OneSignalConfigManager getAppId] + appId:OneSignalIdentifiers.currentAppId pushSubscriptionId:pushSubscriptionId onesignalId:onesignalId influenceParams:params.influenceParams diff --git a/iOS_SDK/OneSignalSDK/Source/OneSignalLifecycleObserver.m b/iOS_SDK/OneSignalSDK/Source/OneSignalLifecycleObserver.m index 58d3b2519..bd20945c2 100644 --- a/iOS_SDK/OneSignalSDK/Source/OneSignalLifecycleObserver.m +++ b/iOS_SDK/OneSignalSDK/Source/OneSignalLifecycleObserver.m @@ -26,6 +26,7 @@ of this software and associated documentation files (the "Software"), to deal */ #import +#import #import "OneSignalLifecycleObserver.h" #import "OneSignalInternal.h" #import "OneSignalCommonDefines.h" @@ -79,7 +80,7 @@ + (void)removeObserver { - (void)didBecomeActive { [OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"application/scene didBecomeActive"]; - if ([OneSignalConfigManager getAppId]) { + if (OneSignalIdentifiers.currentAppId) { [OneSignalTracker onFocus:NO]; let oneSignalLocation = NSClassFromString(ONE_SIGNAL_LOCATION_CLASS_NAME); if (oneSignalLocation != nil && [oneSignalLocation respondsToSelector:@selector(onFocus:)]) { @@ -95,7 +96,7 @@ - (void)didBecomeActive { - (void)willResignActive { [OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"application/scene willResignActive"]; - if ([OneSignalConfigManager getAppId]) { + if (OneSignalIdentifiers.currentAppId) { [OneSignalTracker onFocus:YES]; // TODO: Method no longer exists, transitions into flushing operation repo on backgrounding. // [OneSignal sendTagsOnBackground]; @@ -104,7 +105,7 @@ - (void)willResignActive { - (void)didEnterBackground { [OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"application/scene didEnterBackground"]; - if ([OneSignalConfigManager getAppId]) { + if (OneSignalIdentifiers.currentAppId) { let oneSignalLocation = NSClassFromString(ONE_SIGNAL_LOCATION_CLASS_NAME); if (oneSignalLocation != nil && [oneSignalLocation respondsToSelector:@selector(onFocus:)]) { [OneSignalCoreHelper callSelector:@selector(onFocus:) onObject:oneSignalLocation withArg:NO]; diff --git a/iOS_SDK/OneSignalSDK/Source/OneSignalTracker.m b/iOS_SDK/OneSignalSDK/Source/OneSignalTracker.m index 9e96d059a..19ae24fcf 100644 --- a/iOS_SDK/OneSignalSDK/Source/OneSignalTracker.m +++ b/iOS_SDK/OneSignalSDK/Source/OneSignalTracker.m @@ -31,6 +31,7 @@ #import "OneSignalTracker.h" #import "OneSignalWebView.h" #import +#import #import "OSMacros.h" #import #import "OSFocusTimeProcessorFactory.h" @@ -143,7 +144,7 @@ + (OSFocusCallParams *)createFocusCallParams:(NSArray *)lastInflu [focusInfluenceParams addObject:focusInfluenceParam]; } - return [[OSFocusCallParams alloc] initWithParamsAppId:[OneSignalConfigManager getAppId] + return [[OSFocusCallParams alloc] initWithParamsAppId:OneSignalIdentifiers.currentAppId timeElapsed:timeElapsed influenceParams:focusInfluenceParams onSessionEnded:onSessionEnded]; From 898cde1408ad73833ffd58e84570e9aee4fa516e Mon Sep 17 00:00:00 2001 From: Nan Date: Sun, 31 May 2026 17:19:06 -0700 Subject: [PATCH 4/5] build: declare OneSignalOSCore dep for Extension/Notifications/Outcomes Those subspecs / SPM wrappers ship binaries that now link OneSignalOSCore.framework. Without the declaration, NSE-only integrations via CocoaPods or SPM wouldn't embed it and dyld would fail to load the NSE binary on the first push. --- OneSignal.podspec | 3 +++ OneSignalXCFramework.podspec | 3 +++ Package.swift | 3 +++ 3 files changed, 9 insertions(+) diff --git a/OneSignal.podspec b/OneSignal.podspec index fefa1e087..5f01633cf 100755 --- a/OneSignal.podspec +++ b/OneSignal.podspec @@ -22,17 +22,20 @@ Pod::Spec.new do |s| s.subspec 'OneSignalOutcomes' do |ss| ss.dependency 'OneSignal/OneSignalCore' + ss.dependency 'OneSignal/OneSignalOSCore' ss.vendored_frameworks = 'iOS_SDK/OneSignalSDK/OneSignal_Outcomes/OneSignalOutcomes.xcframework' end s.subspec 'OneSignalExtension' do |ss| ss.dependency 'OneSignal/OneSignalCore' + ss.dependency 'OneSignal/OneSignalOSCore' ss.dependency 'OneSignal/OneSignalOutcomes' ss.vendored_frameworks = 'iOS_SDK/OneSignalSDK/OneSignal_Extension/OneSignalExtension.xcframework' end s.subspec 'OneSignalNotifications' do |ss| ss.dependency 'OneSignal/OneSignalCore' + ss.dependency 'OneSignal/OneSignalOSCore' ss.dependency 'OneSignal/OneSignalOutcomes' ss.dependency 'OneSignal/OneSignalExtension' ss.vendored_frameworks = 'iOS_SDK/OneSignalSDK/OneSignal_Notifications/OneSignalNotifications.xcframework' diff --git a/OneSignalXCFramework.podspec b/OneSignalXCFramework.podspec index c52b83520..1425a14fb 100644 --- a/OneSignalXCFramework.podspec +++ b/OneSignalXCFramework.podspec @@ -22,17 +22,20 @@ Pod::Spec.new do |s| s.subspec 'OneSignalOutcomes' do |ss| ss.dependency 'OneSignalXCFramework/OneSignalCore' + ss.dependency 'OneSignalXCFramework/OneSignalOSCore' ss.vendored_frameworks = 'iOS_SDK/OneSignalSDK/OneSignal_Outcomes/OneSignalOutcomes.xcframework' end s.subspec 'OneSignalExtension' do |ss| ss.dependency 'OneSignalXCFramework/OneSignalCore' + ss.dependency 'OneSignalXCFramework/OneSignalOSCore' ss.dependency 'OneSignalXCFramework/OneSignalOutcomes' ss.vendored_frameworks = 'iOS_SDK/OneSignalSDK/OneSignal_Extension/OneSignalExtension.xcframework' end s.subspec 'OneSignalNotifications' do |ss| ss.dependency 'OneSignalXCFramework/OneSignalCore' + ss.dependency 'OneSignalXCFramework/OneSignalOSCore' ss.dependency 'OneSignalXCFramework/OneSignalOutcomes' ss.dependency 'OneSignalXCFramework/OneSignalExtension' ss.vendored_frameworks = 'iOS_SDK/OneSignalSDK/OneSignal_Notifications/OneSignalNotifications.xcframework' diff --git a/Package.swift b/Package.swift index 3dc74dd76..47ec8302d 100644 --- a/Package.swift +++ b/Package.swift @@ -75,6 +75,7 @@ let package = Package( "OneSignalNotifications", "OneSignalExtension", "OneSignalOutcomes", + "OneSignalOSCore", "OneSignalCore" ], path: "OneSignalNotificationsWrapper" @@ -84,6 +85,7 @@ let package = Package( dependencies: [ "OneSignalExtension", "OneSignalOutcomes", + "OneSignalOSCore", "OneSignalCore" ], path: "OneSignalExtensionWrapper" @@ -92,6 +94,7 @@ let package = Package( name: "OneSignalOutcomesWrapper", dependencies: [ "OneSignalOutcomes", + "OneSignalOSCore", "OneSignalCore" ], path: "OneSignalOutcomesWrapper" From 7251691a91c1c6941eddb0a776d7cbd2ca0764a4 Mon Sep 17 00:00:00 2001 From: Nan Date: Mon, 1 Jun 2026 10:43:17 -0700 Subject: [PATCH 5/5] nit: spacing --- .../OneSignalInAppMessagesTests/IAMIntegrationTests.swift | 4 ++-- .../OSLiveActivitiesExecutorTests.swift | 2 +- .../OneSignalSDK/OneSignalOSCore/Source/OneSignalConfig.swift | 2 +- .../OneSignalUserTests/CustomEventsIntegrationTests.swift | 2 +- .../Executors/OSCustomEventsExecutorTests.swift | 2 +- .../OneSignalUserTests/Executors/UserExecutorTests.swift | 2 +- .../OneSignalSDK/OneSignalUserTests/OneSignalUserTests.swift | 2 +- .../OneSignalUserTests/SwitchUserIntegrationTests.swift | 2 +- .../OneSignalUserTests/UserConcurrencyTests.swift | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/iOS_SDK/OneSignalSDK/OneSignalInAppMessagesTests/IAMIntegrationTests.swift b/iOS_SDK/OneSignalSDK/OneSignalInAppMessagesTests/IAMIntegrationTests.swift index cf1e824ec..9efcb6f51 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalInAppMessagesTests/IAMIntegrationTests.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalInAppMessagesTests/IAMIntegrationTests.swift @@ -55,7 +55,7 @@ final class IAMIntegrationTests: XCTestCase { /* Setup */ OneSignalCoreImpl.setSharedClient(MockOneSignalClient()) // App ID is set because there are guards against nil App ID - OneSignalIdentifiers.currentAppId = "test-app-id" + OneSignalIdentifiers.currentAppId = "test-app-id" // 1. Pause IAMs OneSignalInAppMessages.__paused(true) @@ -82,7 +82,7 @@ final class IAMIntegrationTests: XCTestCase { OneSignalCoreImpl.setSharedClient(client) // 1. App ID is set because there are guards against nil App ID - OneSignalIdentifiers.currentAppId = "test-app-id" + OneSignalIdentifiers.currentAppId = "test-app-id" // 2. Set up mock responses for the anonymous user, as the user needs an OSID MockUserRequests.setDefaultCreateAnonUserResponses(with: client) diff --git a/iOS_SDK/OneSignalSDK/OneSignalLiveActivitiesTests/OSLiveActivitiesExecutorTests.swift b/iOS_SDK/OneSignalSDK/OneSignalLiveActivitiesTests/OSLiveActivitiesExecutorTests.swift index 675f466c5..6feb7c122 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalLiveActivitiesTests/OSLiveActivitiesExecutorTests.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalLiveActivitiesTests/OSLiveActivitiesExecutorTests.swift @@ -42,7 +42,7 @@ final class OSLiveActivitiesExecutorTests: XCTestCase { OneSignalCoreMocks.clearUserDefaults() OneSignalUserMocks.reset() // App ID is set because User Manager has guards against nil App ID - OneSignalIdentifiers.currentAppId = "test-app-id" + OneSignalIdentifiers.currentAppId = "test-app-id" // Temp. logging to help debug during testing OneSignalLog.setLogLevel(.LL_VERBOSE) } diff --git a/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OneSignalConfig.swift b/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OneSignalConfig.swift index 9af2a3080..67e44e54e 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OneSignalConfig.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OneSignalConfig.swift @@ -28,7 +28,7 @@ import Foundation import OneSignalCore -/// SDK-level configuration / readiness predicates. Replaces +/// SDK-level configuration / readiness predicates @objc(OneSignalConfig) public final class OneSignalConfig: NSObject { diff --git a/iOS_SDK/OneSignalSDK/OneSignalUserTests/CustomEventsIntegrationTests.swift b/iOS_SDK/OneSignalSDK/OneSignalUserTests/CustomEventsIntegrationTests.swift index be80f3310..e64b057dc 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUserTests/CustomEventsIntegrationTests.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUserTests/CustomEventsIntegrationTests.swift @@ -38,7 +38,7 @@ final class CustomEventsIntegrationTests: XCTestCase { override func setUpWithError() throws { OneSignalCoreMocks.clearUserDefaults() OneSignalUserMocks.reset() - OneSignalIdentifiers.currentAppId = "test-app-id" + OneSignalIdentifiers.currentAppId = "test-app-id" OneSignalLog.setLogLevel(.LL_VERBOSE) } diff --git a/iOS_SDK/OneSignalSDK/OneSignalUserTests/Executors/OSCustomEventsExecutorTests.swift b/iOS_SDK/OneSignalSDK/OneSignalUserTests/Executors/OSCustomEventsExecutorTests.swift index 8f4154fc2..3ea47ff03 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUserTests/Executors/OSCustomEventsExecutorTests.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUserTests/Executors/OSCustomEventsExecutorTests.swift @@ -62,7 +62,7 @@ final class OSCustomEventsExecutorTests: XCTestCase { override func setUpWithError() throws { OneSignalCoreMocks.clearUserDefaults() OneSignalUserMocks.reset() - OneSignalIdentifiers.currentAppId = "test-app-id" + OneSignalIdentifiers.currentAppId = "test-app-id" OneSignalLog.setLogLevel(.LL_VERBOSE) } diff --git a/iOS_SDK/OneSignalSDK/OneSignalUserTests/Executors/UserExecutorTests.swift b/iOS_SDK/OneSignalSDK/OneSignalUserTests/Executors/UserExecutorTests.swift index f52163427..f914bb4be 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUserTests/Executors/UserExecutorTests.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUserTests/Executors/UserExecutorTests.swift @@ -58,7 +58,7 @@ final class UserExecutorTests: XCTestCase { OneSignalCoreMocks.clearUserDefaults() OneSignalUserMocks.reset() // App ID is set because requests have guards against null App ID - OneSignalIdentifiers.currentAppId = "test-app-id" + OneSignalIdentifiers.currentAppId = "test-app-id" // Temp. logging to help debug during testing OneSignalLog.setLogLevel(.LL_VERBOSE) } diff --git a/iOS_SDK/OneSignalSDK/OneSignalUserTests/OneSignalUserTests.swift b/iOS_SDK/OneSignalSDK/OneSignalUserTests/OneSignalUserTests.swift index c8e65f7b2..9cf4652dd 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUserTests/OneSignalUserTests.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUserTests/OneSignalUserTests.swift @@ -41,7 +41,7 @@ final class OneSignalUserTests: XCTestCase { OneSignalCoreMocks.clearUserDefaults() OneSignalUserMocks.reset() // App ID is set because User Manager has guards against nil App ID - OneSignalIdentifiers.currentAppId = "test-app-id" + OneSignalIdentifiers.currentAppId = "test-app-id" // Temp. logging to help debug during testing OneSignalLog.setLogLevel(.LL_VERBOSE) } diff --git a/iOS_SDK/OneSignalSDK/OneSignalUserTests/SwitchUserIntegrationTests.swift b/iOS_SDK/OneSignalSDK/OneSignalUserTests/SwitchUserIntegrationTests.swift index b9ae4f6a4..2c598b6bb 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUserTests/SwitchUserIntegrationTests.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUserTests/SwitchUserIntegrationTests.swift @@ -13,7 +13,7 @@ final class SwitchUserIntegrationTests: XCTestCase { OneSignalCoreMocks.clearUserDefaults() OneSignalUserMocks.reset() // App ID is set because User Manager has guards against nil App ID - OneSignalIdentifiers.currentAppId = "test-app-id" + OneSignalIdentifiers.currentAppId = "test-app-id" // Temp. logging to help debug during testing OneSignalLog.setLogLevel(.LL_VERBOSE) } diff --git a/iOS_SDK/OneSignalSDK/OneSignalUserTests/UserConcurrencyTests.swift b/iOS_SDK/OneSignalSDK/OneSignalUserTests/UserConcurrencyTests.swift index 106d4cfa6..94d3f4388 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUserTests/UserConcurrencyTests.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUserTests/UserConcurrencyTests.swift @@ -41,7 +41,7 @@ final class UserConcurrencyTests: XCTestCase { OneSignalCoreMocks.clearUserDefaults() OneSignalUserMocks.reset() // App ID is set because User Manager has guards against nil App ID - OneSignalIdentifiers.currentAppId = "test-app-id" + OneSignalIdentifiers.currentAppId = "test-app-id" // Temp. logging to help debug during testing OneSignalLog.setLogLevel(.LL_VERBOSE) }