@@ -215,6 +215,16 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager {
215215
216216 OneSignalLog . onesignalLog ( . LL_VERBOSE, message: " OneSignalUserManager calling start " )
217217
218+ // The model stores load their in-memory `models` dict once in their initializer.
219+ // If the singleton was first touched while protected data was unavailable (iOS app
220+ // prewarm), that read returned nil and the dicts are empty. The gate above ensures
221+ // `start()` only proceeds when protected data is available, but the stores need to
222+ // be refreshed here so Path 1's cache check can see what's on disk.
223+ identityModelStore. refresh ( )
224+ propertiesModelStore. refresh ( )
225+ subscriptionModelStore. refresh ( )
226+ pushSubscriptionModelStore. refresh ( )
227+
218228 OSNotificationsManager . delegate = self
219229
220230 var hasCachedUser = false
@@ -266,25 +276,6 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager {
266276 OneSignalUserDefaults . initShared ( ) . saveString ( forKey: OSUD_PUSH_SUBSCRIPTION_ID, withValue: legacyPlayerId)
267277 OneSignalUserDefaults . initStandard ( ) . removeValue ( forKey: OSUD_LEGACY_PLAYER_ID)
268278 OneSignalUserDefaults . initShared ( ) . removeValue ( forKey: OSUD_LEGACY_PLAYER_ID)
269- } else if !hasCachedUser, _user == nil ,
270- let cachedSubId = OSResilientStorage . string ( forKey: OSResilientStorage . keySubscriptionId) , !cachedSubId. isEmpty {
271- // Path 2.5. Model stores looked empty, but the resilient cache shows we've
272- // initialized before — the prewarm-before-first-unlock case where
273- // OSModelStore's in-memory dict was loaded empty during locked storage and
274- // never re-read. Recover the existing identity locally; missing properties /
275- // aliases will rehydrate on the next fetchUser. Do NOT call setNewInternalUser
276- // (which would write stub models through modelStore.add) — that would
277- // overwrite the real cached models on disk.
278- let cachedOnesignalId = OSResilientStorage . string ( forKey: OSResilientStorage . keyOneSignalId)
279- OneSignalLog . onesignalLog ( . LL_DEBUG, message: " OneSignalUserManager: recovering user from resilient cache subscription_id= \( cachedSubId) onesignal_id= \( cachedOnesignalId ?? " (nil) " ) " )
280- let identityModel = OSIdentityModel ( aliases: nil , changeNotifier: OSEventProducer ( ) )
281- if let onesignalId = cachedOnesignalId, !onesignalId. isEmpty {
282- identityModel. hydrate ( [ OS_ONESIGNAL_ID: onesignalId] )
283- }
284- addIdentityModelToRepo ( identityModel)
285- let propertiesModel = OSPropertiesModel ( changeNotifier: OSEventProducer ( ) )
286- let pushSubscriptionModel = createDefaultPushSubscription ( subscriptionId: cachedSubId)
287- _user = OSUserInternalImpl ( identityModel: identityModel, propertiesModel: propertiesModel, pushSubscriptionModel: pushSubscriptionModel)
288279 } else {
289280 // Path 3. Creates an anonymous user if there isn't one in the cache nor a legacy player
290281 if _user == nil {
@@ -899,28 +890,21 @@ extension OneSignalUserManagerImpl {
899890 guard !OneSignalConfig. shouldAwaitAppIdAndLogMissingPrivacyConsent ( forMethod: " pushSubscription.id " ) else {
900891 return nil
901892 }
902- // Fall back to the live `_user.pushSubscriptionModel` so the prewarm-recovery
903- // path (where the model isn't added to the store) still returns the right value.
904893 return pushSubscriptionModelStore. getModel ( key: OS_PUSH_SUBSCRIPTION_MODEL_KEY) ? . subscriptionId
905- ?? OneSignalUserManagerImpl . sharedInstance. _user? . pushSubscriptionModel. subscriptionId
906894 }
907895
908896 public var token : String ? {
909897 guard !OneSignalConfig. shouldAwaitAppIdAndLogMissingPrivacyConsent ( forMethod: " pushSubscription.token " ) else {
910898 return nil
911899 }
912900 return pushSubscriptionModelStore. getModel ( key: OS_PUSH_SUBSCRIPTION_MODEL_KEY) ? . address
913- ?? OneSignalUserManagerImpl . sharedInstance. _user? . pushSubscriptionModel. address
914901 }
915902
916903 public var optedIn : Bool {
917904 guard !OneSignalConfig. shouldAwaitAppIdAndLogMissingPrivacyConsent ( forMethod: " pushSubscription.optedIn " ) else {
918905 return false
919906 }
920- if let storeModel = pushSubscriptionModelStore. getModel ( key: OS_PUSH_SUBSCRIPTION_MODEL_KEY) {
921- return storeModel. optedIn
922- }
923- return OneSignalUserManagerImpl . sharedInstance. _user? . pushSubscriptionModel. optedIn ?? false
907+ return pushSubscriptionModelStore. getModel ( key: OS_PUSH_SUBSCRIPTION_MODEL_KEY) ? . optedIn ?? false
924908 }
925909
926910 /**
0 commit comments