firebase / firebase/firebase-ios-sdk
Make Firebase components initializable without access to disk resources (Keychain)
- Dominant language
- C++
- Stars
- 6.7k
- Forks
- 1.8k
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 75
Description
Currently, Firebase requires access to the keychain on startup to do a couple things, including:
- Check for the existence of a logged in user
- Check for the existence of a previous installation token
With [app pre-warming](https://developer.apple.com/documentation/uikit/app_and_environment/responding_to_the_launch_of_your_app/about_the_app_launch_sequence), the app may be launched without user interaction up to the `UIApplicationMain` function. This documentation doesn't mention anything about SwiftUI, but the reports we've been receiving (#10200) suggest SwiftUI classes may be initialized during pre-warming. Our documentation has been updated to tell users to initialize Firebase in a `UIApplicationDelegate` implementation instead, but since SwiftUI doesn't guarantee when views will be instantiated wrt keychain availability, this method works only coincidentally and has the unpleasant side effect of requiring people who use SwiftUI to lazily reference Firebase everywhere or their Firebase references may be [invoked by SwiftUI initializing a view](https://stackoverflow.com/questions/74430846/firebase-exception-error-for-macos-app-xcode) while data protection is still on.
Ultimately Firebase needs to work without assuming all resources are available on initialization.
Related reading:
- [Cookpad running into a similar issue](https://sourcediving.com/solving-mysterious-logout-issues-on-ios-15-8b818c089466)
- [Apple dev forums thread](https://developer.apple.com/forums/thread/685685)
Contributor guide
Research direction
Start at the UIApplicationMain and UIApplicationDelegate initialization boundary, then trace which Firebase startup checks access the Keychain for the logged-in user and installation token. Confirm the behavior against SwiftUI pre-warming scenarios; done means Firebase components can initialize when those disk-backed resources are unavailable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- mobile-dev, security
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100