-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SwiftUI and Objective-C inter-op with Swizzling #10417
Comments
I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight. |
@fabrizioCorut Thank you for the very thorough Issue report. In the short-term, we're working to update our documentation and in the longer term, we're exploring ways to support a more natural SwiftUI lifecycle. |
How do you disable swizzling? I have a SwiftUI Mac app with a custom app delegate. Sorry if this is a real novice question! |
Hey @peternowell, you can disable swizzling by adding the For now, if you're using SwiftUI, you should disable swizzling. |
Is this still a bug? Has been open for 2 years |
Description
First of all, let's define some terminology. I will refer to:
SwiftUI.App
protocol, it being marked by the new@main
annotation; This app can still haveAppDelegate
andSceneDelegate
implementations, but those will not be the entry point of the application;Using
FirebaseApp
in a "SwiftUI app" is very confusing and there is no guidance as to where to correctly place theFirebaseApp.configure()
method call and more importantly, why place it where it should be placed.Some of my observations from placing the
FirebaseApp.configure()
call in different places:Configuration
FirebaseApp.configure()
in theApp's
init
methodWorks, but some of the components from
Firebase
are reliant on theUIApplication.shared
instance, which is not initialized at the time of the call; ❌Setup:
Concrete issue example from
FIRAuth.protectedDataInitialization
:at this time and point, as far as I could investigate and test, the
application is NULL
and that doesn't seem to change during the lifetime of the app in this setup.Obs: swizzling on/ off does not solve the behaviour described.
FirebaseApp.configure()
inUIApplicationDelegate.application(_, didFinishLaunchingWithOptions:)
Solves the problem described above since at init time the
UIApplication.shared
exists. But this is where the discussion gets interesting.UIApplicationDelegate
methods do not get correctly called; ❌ the investigation that led me to this conclusion is thetap DynamicLink -> app not installed -> install app -> navigate to the actual deeplink
scenario. I was simply not getting theUIApplicationDelegate.application(_:open:options:)
or any other method, for what is worth, called. A couple of hours later and down the rabbit hole I have discovered thatSwiftUI
creates its ownAppDelegate
wrapper over the actualMyAppDelegate
declared in my application like:The wrapper class is:
SwiftUI.AppDelegate
. which looks like:The issue with this wrapper class is that it's not fully interoperable with
Objective-C runtime
causing theswizzling
to fail.Reproducing the issue
Obs: does not seem to be an iOS specific issue since it doesn't work on iOS 15 or iOS 16 either.
Reproduction steps:
SwiftUI
application;@UIApplicationDelegateAdaptor(AppDelegate)
;FirebaseApp.configure()
fromUIApplicationDelegate.application(_, didFinishLaunchingWithOptions:)
;Firebase SDK Version
9.6.0
Xcode Version
14.0.1
Installation Method
Swift Package Manager
Firebase Product(s)
Analytics, Authentication, Database, DynamicLinks, Firestore, Functions, Remote Config
Targeted Platforms
iOS
Relevant Log Output
Setup:
FirebaseApp.configure()
called in from aSwiftUI app
fromUIApplicationDelegate.application(_, didFinishLaunchingWithOptions:)
.From: GULAppDelegateSwizzler.createSubclassWithObject:(id<GULApplicationDelegate>)appDelegate just before
If using Swift Package Manager, the project's Package.resolved
Expand
Package.resolved
snippetThe text was updated successfully, but these errors were encountered: