DEV Community

Samir Moukhliss
Samir Moukhliss

Posted on

How I Solved the "Auto-Init" Privacy Leak in iOS & Android Apps (and Open-Sourced the Code)

If you are building a mobile app with third-party SDKs—Firebase, Facebook, AppsFlyer, AdMob, Adjust—you probably have a hidden GDPR/CCPA compliance risk sitting right in your AppDelegate or Application class.

It’s the "Auto-Init" leak.

Most tracking SDKs are designed to initialize immediately on app startup. They start collecting device data, analytics, and advertising identifiers before your user ever sees a consent prompt, let alone clicks "Accept". Even if you load a web-based consent banner in a WebView a few seconds later, the data has already left the device.

I realized there wasn't a clean, native, lightweight way to intercept this at the platform level, so I built one.

Today, I’m open-sourcing the CookiePrime Native Consent SDKs for iOS and Android. They detect tracking SDKs, present a native consent UI, and strictly block third-party trackers until explicit user consent is granted.

Here is how they work under the hood, and where you can grab the code.


🛑 The iOS Solution: Deferred SDK Initialization

For iOS, the biggest challenge was ensuring zero pre-consent data collection without making the developer write spaghetti code to manually delay every SDK.

The CookiePrime iOS SDK solves this using a Deferred SDK Loader. Instead of initializing your tracking SDKs directly in didFinishLaunchingWithOptions or your @main App struct, you register them with the consent manager.

ConsentSDK.shared.deferSDK("FirebaseAnalytics", category: "analytics") {
    FirebaseApp.configure()
    FirebaseAnalytics.Analytics.logEvent(AnalyticsEventAppOpen, parameters: nil)
}
Enter fullscreen mode Exit fullscreen mode

Key iOS Features:

  • Native UI: Built with SwiftUI and UIKit components. It finds the topmost view controller automatically to present the dialog.
  • Complete Blocking: SDK code never executes without explicit consent for that specific category.
  • Privacy Manifest Included: Ships with PrivacyInfo.xcprivacy to satisfy Apple’s latest App Store submission requirements.

🤖 The Android Solution: Runtime Configuration & Sync

Android requires a slightly different approach due to background services and offline states.

The CookiePrime Android SDK (Source) automatically detects which tracking SDKs are compiled into your app and configures them at runtime based on the user's choices.

class MyApp : Application() {
    override fun onCreate() {
        super.onCreate()
        CookiePrime.init(this, "YOUR_LICENSE_KEY") { 
            enableDebug = true 
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Key Android Features:

  • Google Consent Mode v2 & IAB TCF 2.2: Automatically sets ad_storage, analytics_storage, and ad personalization signals, while generating an IAB-compatible TC string.
  • Offline Support: Uses Room database to store consent states locally and Android WorkManager to sync the proof of consent once the network is available.
  • Material Design: Provides a clean, compliant UI with per-category toggles right out of the box.

🛠 Try It Out (Code & Examples)

I wanted these to be completely transparent so developers can see exactly how the blocking and state-management work. Both SDKs are written in pure Swift and Kotlin.

Want to just drop the Android version into your app to see it in action?
I have uploaded the compiled .aar release file along with two example APKs showing the banner in a real app environment here:
👉 CookiePrime Android AAR & Examples


Let’s Discuss

If you are building mobile apps that rely on analytics or monetization SDKs, I'd love your feedback. Have you run into the auto-init problem? How are you currently managing Consent Mode v2 natively on mobile?

Check out the repos, drop a star if you find the architecture useful, and let me know your thoughts in the comments!

Top comments (1)

Collapse
 
userxnom profile image
Abdullah Naseer •

The deferred loader on iOS is the part that clicked for me — registering FirebaseAnalytics with deferSDK instead of calling FirebaseApp.configure() in didFinishLaunchingWithOptions makes the pre-consent leak concrete rather than theoretical. On Android, how do you handle SDKs that auto-init through a ContentProvider before Application.onCreate even runs — does CookiePrime catch those too, or is that a gap you still have to work around per SDK?