From 7ec4d9c96fed2e8d0170860a9a45caea399119b7 Mon Sep 17 00:00:00 2001 From: Nan Date: Fri, 1 Dec 2023 11:55:40 -0800 Subject: [PATCH 1/2] save subscription ID when upgrading from v3 We were not saving the OSUD_PUSH_SUBSCRIPTION_ID to user defaults when we detected a legacy player ID and proceed with upgrading. It was only saved from create user responses that hydrate the subscription model, which does not happen on v3 -> v5 upgrade. --- .../OneSignalUser/Source/OneSignalUserManagerImpl.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift index f58aa1208..28855c0af 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift @@ -228,6 +228,7 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager { if let legacyPlayerId = OneSignalUserDefaults.initShared().getSavedString(forKey: OSUD_LEGACY_PLAYER_ID, defaultValue: nil) { OneSignalLog.onesignalLog(.LL_DEBUG, message: "OneSignalUserManager: creating user linked to legacy subscription \(legacyPlayerId)") createUserFromLegacyPlayer(legacyPlayerId) + OneSignalUserDefaults.initShared().saveString(forKey: OSUD_PUSH_SUBSCRIPTION_ID, withValue: legacyPlayerId) OneSignalUserDefaults.initStandard().removeValue(forKey: OSUD_LEGACY_PLAYER_ID) OneSignalUserDefaults.initShared().removeValue(forKey: OSUD_LEGACY_PLAYER_ID) } else { From eb049f4d88e49af2693898fbd81d5619c0b36610 Mon Sep 17 00:00:00 2001 From: Nan Date: Fri, 1 Dec 2023 12:06:35 -0800 Subject: [PATCH 2/2] Save push subscription ID on app start Because of a bug prior to v5.0.5, players that upgraded from v3 -> v5 were missing the player ID in cache for sending to notification opened and notification received endpoints. Now, every time app cold starts, as part of the push subscription model checking itself for updates, we will cache its subscription ID if non-empty. --- .../OneSignalUser/Source/OSSubscriptionModel.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSSubscriptionModel.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSSubscriptionModel.swift index 046b61195..ca265abba 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSSubscriptionModel.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSSubscriptionModel.swift @@ -425,6 +425,9 @@ extension OSSubscriptionModel { netType = OSNetworkingUtils.getNetType() as? Int // sdkType ?? // isRooted ?? + if type == .push && !(subscriptionId ?? "").isEmpty { + OneSignalUserDefaults.initShared().saveString(forKey: OSUD_PUSH_SUBSCRIPTION_ID, withValue: subscriptionId) + } } enum OSPushPropertyChanged {