Skip to content

Commit 0789138

Browse files
committed
refactor: drop redundant OSNotificationsManager pushSubscriptionId cache
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.
1 parent 21ed813 commit 0789138

3 files changed

Lines changed: 3 additions & 20 deletions

File tree

iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,6 @@ NS_SWIFT_NAME(onClick(event:));
121121

122122
@property (class, readonly) OneSignalNotificationSettings* _Nonnull osNotificationSettings;
123123

124-
// This is set by the user module
125-
+ (void)setPushSubscriptionId:(NSString *_Nullable)pushSubscriptionId;
126-
127124
+ (void)handleWillShowInForegroundForNotification:(OSNotification *_Nonnull)notification completion:(OSNotificationDisplayResponse _Nonnull)completion;
128125
+ (void)handleNotificationActionWithUrl:(NSString* _Nullable)url actionID:(NSString* _Nonnull)actionID;
129126
+ (void)clearBadgeCount:(BOOL)fromNotifOpened fromClearAll:(BOOL)fromClearAll;

iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.m

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -232,17 +232,6 @@ + (NSString*)pushToken {
232232
return _pushToken;
233233
}
234234

235-
static NSString *_pushSubscriptionId;
236-
+ (NSString*)pushSubscriptionId {
237-
if (!_pushSubscriptionId) {
238-
_pushSubscriptionId = OneSignalIdentifiers.subscriptionId;
239-
}
240-
return _pushSubscriptionId;
241-
}
242-
+ (void)setPushSubscriptionId:(NSString *)pushSubscriptionId {
243-
_pushSubscriptionId = pushSubscriptionId;
244-
}
245-
246235
#pragma clang diagnostic push
247236
#pragma clang diagnostic ignored "-Wundeclared-selector"
248237
+ (void)startSwizzling {
@@ -784,7 +773,7 @@ + (void)submitNotificationOpened:(NSString*)messageId {
784773
NSString* lastMessageId = [standardUserDefaults getSavedStringForKey:OSUD_LAST_MESSAGE_OPENED defaultValue:nil];
785774
//Only submit request if messageId not nil and: (lastMessage is nil or not equal to current one)
786775
if(messageId && (!lastMessageId || ![lastMessageId isEqualToString:messageId])) {
787-
[OneSignalCoreImpl.sharedClient executeRequest:[OSRequestSubmitNotificationOpened withUserId:[self pushSubscriptionId]
776+
[OneSignalCoreImpl.sharedClient executeRequest:[OSRequestSubmitNotificationOpened withUserId:OneSignalIdentifiers.subscriptionId
788777
appId:[OneSignalConfigManager getAppId]
789778
wasOpened:YES
790779
messageId:messageId

iOS_SDK/OneSignalSDK/OneSignalUser/Source/Executors/OSUserExecutor.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -528,11 +528,8 @@ extension OSUserExecutor {
528528
areTokensEqual(tokenA: originalPushToken, tokenB: subModel["token"] as? String)
529529
{
530530
OneSignalUserManagerImpl.sharedInstance.pushSubscriptionModel?.hydrate(subModel)
531-
if let subId = subModel["id"] as? String {
532-
OSNotificationsManager.setPushSubscriptionId(subId)
533-
if addNewRecords {
534-
newRecordsState.add(subId)
535-
}
531+
if addNewRecords, let subId = subModel["id"] as? String {
532+
newRecordsState.add(subId)
536533
}
537534
break
538535
}

0 commit comments

Comments
 (0)