Skip to content

Commit 2c9b980

Browse files
committed
wip
1 parent ae07b4e commit 2c9b980

2 files changed

Lines changed: 23 additions & 7 deletions

File tree

iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,10 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager {
274274
OneSignalLog.onesignalLog(.LL_DEBUG, message: "OneSignalUserManager: creating user linked to legacy subscription \(legacyPlayerId)")
275275
createUserFromLegacyPlayer(legacyPlayerId)
276276
OneSignalUserDefaults.initShared().saveString(forKey: OSUD_PUSH_SUBSCRIPTION_ID, withValue: legacyPlayerId)
277+
// Mirror to OSResilientStorage as well — createDefaultPushSubscription sets the id
278+
// via the initializer, so subscriptionId.didSet (which normally writes the mirror)
279+
// does not fire here. Keeps the prewarm fallback populated for migrated v3 players.
280+
OSResilientStorage.setString(legacyPlayerId, forKey: OSResilientStorage.keySubscriptionId)
277281
OneSignalUserDefaults.initStandard().removeValue(forKey: OSUD_LEGACY_PLAYER_ID)
278282
OneSignalUserDefaults.initShared().removeValue(forKey: OSUD_LEGACY_PLAYER_ID)
279283
} else {

iOS_SDK/OneSignalSDK/Source/OneSignal.m

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -469,13 +469,6 @@ + (void)init {
469469
static _Atomic(BOOL) gProtectedDataAvailable = NO;
470470
static dispatch_once_t protectedDataOnce;
471471
dispatch_once(&protectedDataOnce, ^{
472-
// Seed the cache on the main thread once. UIApplication APIs are main-thread-only.
473-
// On a normal launch this resolves to YES near-immediately; on a prewarm launch
474-
// before first unlock it stays NO and the notification will flip it later.
475-
dispatch_async(dispatch_get_main_queue(), ^{
476-
atomic_store(&gProtectedDataAvailable, UIApplication.sharedApplication.isProtectedDataAvailable);
477-
});
478-
479472
NSNotificationCenter *center = NSNotificationCenter.defaultCenter;
480473
[center addObserverForName:UIApplicationProtectedDataDidBecomeAvailable
481474
object:nil
@@ -497,6 +490,25 @@ + (void)init {
497490
OneSignalConfig.isProtectedDataAvailableProvider = ^BOOL {
498491
return atomic_load(&gProtectedDataAvailable);
499492
};
493+
494+
// Seed the cached flag. UIApplication APIs are main-thread-only. `initialize` is normally
495+
// called from `application:didFinishLaunchingWithOptions:` on the main thread, so seed
496+
// synchronously here — that way the flag is correct before `startUserManager` runs later
497+
// in this same `init`. If we're off the main thread, hop to main to read it; once it
498+
// resolves to available, re-drive `start()`, because the synchronous `start()` below will
499+
// have been gated out and a normal (already-unlocked) launch never posts
500+
// UIApplicationProtectedDataDidBecomeAvailable to re-drive it.
501+
if ([NSThread isMainThread]) {
502+
atomic_store(&gProtectedDataAvailable, UIApplication.sharedApplication.isProtectedDataAvailable);
503+
} else {
504+
dispatch_async(dispatch_get_main_queue(), ^{
505+
BOOL available = UIApplication.sharedApplication.isProtectedDataAvailable;
506+
atomic_store(&gProtectedDataAvailable, available);
507+
if (available) {
508+
[OneSignalUserManagerImpl.sharedInstance start];
509+
}
510+
});
511+
}
500512
});
501513

502514
// TODO: We moved this check to the top of this method, we should test this.

0 commit comments

Comments
 (0)