Skip to content

Commit 1b44eed

Browse files
committed
add protected-data gate to readiness predicate
Adds `isProtectedDataAvailableProvider` injection point and a third branch in `shouldAwaitAppIdAndLogMissingPrivacyConsent` so SDK ops defer when device-protected storage isn't readable (iOS prewarm before first unlock). NSE callers (provider nil) keep prior behavior.
1 parent c9dc134 commit 1b44eed

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OneSignalConfig.swift

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,17 @@ import OneSignalCore
3232
@objc(OneSignalConfig)
3333
public final class OneSignalConfig: NSObject {
3434

35-
/// Returns true when the SDK shouldn't perform an operation yet because either:
35+
/// Returns whether device-protected storage is currently readable. The main app target sets
36+
/// this once at `+OneSignal.init`; the predicate calls it on every gate check from
37+
/// arbitrary threads, so the closure must be cheap and thread-safe. Left nil in app
38+
/// extensions (NSE) where `UIApplication` is unavailable — nil is treated as available,
39+
/// which is correct for NSE since it reads identifiers through `OSResilientStorage`.
40+
@objc public static var isProtectedDataAvailableProvider: (() -> Bool)?
41+
42+
/// Returns true when the SDK shouldn't perform an operation yet because:
3643
/// * `app_id` hasn't been set via `OneSignal.initialize`, or
37-
/// * the host app hasn't granted privacy consent (per `OSPrivacyConsentController`).
44+
/// * the host app hasn't granted privacy consent, or
45+
/// * device storage isn't readable yet (iOS prewarm before first unlock).
3846
@objc public static func shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod methodName: String?) -> Bool {
3947
var shouldAwait = false
4048
if OneSignalIdentifiers.currentAppId == nil {
@@ -46,6 +54,12 @@ public final class OneSignalConfig: NSObject {
4654
if OSPrivacyConsentController.shouldLogMissingPrivacyConsentError(withMethodName: methodName) {
4755
shouldAwait = true
4856
}
57+
if let provider = isProtectedDataAvailableProvider, !provider() {
58+
if let methodName {
59+
OneSignalLog.onesignalLog(.LL_DEBUG, message: "\(methodName) deferred: device-protected storage is not yet available")
60+
}
61+
shouldAwait = true
62+
}
4963
return shouldAwait
5064
}
5165
}

0 commit comments

Comments
 (0)