The solution was to use it on appear, like so:
@main
struct ExampleApp: App {
@UIApplicationDelegateAdaptor private var appDelegate: AppDelegate
var body: some Scene {
WindowGroup {
ContentView()
.onAppear(perform: {
appDelegate.app = self
})
}
}
}
And inside AppDeligate it should start like this:
class AppDelegate: NSObject, UIApplicationDelegate {
var app: ExampleApp?