I did a small prototype which uses Firebase Cloud Messaging and the new SwiftUI 2 app life cycle. I added a custom AppDelegate via
@UIApplicationDelegateAdaptor(AppDelegate.self) var delegate
and disabled method swizzeling for FCM to work. Everything is working as expected.
Today a colleague asked me, if one can get that delegate object via UIApplication.shared.delegate
. So I gave it a shot and noticed that there seems to be two different AppDelegate objects:
po delegate
prints:
<MyProject.AppDelegate: 0x6000009183c0>
where as po UIApplication.shared.delegate
prints:
▿ Optional<UIApplicationDelegate>
▿ some : <SwiftUI.AppDelegate: 0x600000b58ca0>
Now I'm wondering what is the correct way of accessing the AppDelegate? Should one get it via an @EnvironmentalObject
and pass it along all views? Or use the old fashioned way via UIApplication
?
Additionally I would like to understand why I end up with two AppDelegates.