UIApplicationDelegateAdaptor won't do anything

I just created a SwiftUI project in Xcode 12.5 (12E262) and changed my main App class to

import SwiftUI

class AppDelegate: UIResponder, UIApplicationDelegate {

	func applicationDidFinishLaunching(_ application: UIApplication) {
		print("applicationDidFinishLaunching")
	}

	func applicationDidBecomeActive(_ application: UIApplication) {
		print("applicationDidBecomeActive")
	}

	func applicationDidEnterBackground(_ application: UIApplication) {
		print("applicationDidEnterBackground")
	}

	func applicationWillEnterForeground(_ application: UIApplication) {
		print("applicationWillEnterForeground")
	}

	func applicationWillTerminate(_ application: UIApplication) {
		print("applicationWillTerminate")
	}
}


@main
struct SwiftUIAppDelegateTestsApp: App {

	@UIApplicationDelegateAdaptor(AppDelegate.self) var delegate

    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

No app delegate method is called.

Should the App Delegate listed anywhere else e.g. in the build settings or info plist?

Answered by workingdogintokyo in 682113022

your functions signatures are wrong. For example, if you use this it works:

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
        print("\n-------> applicationDidFinishLaunching")
        return true
    }

Are you using Firebase in your project? If yes, try disabling the Firebase Swizzling magic in your application's plist file and it should work 😅

    <key>FirebaseAppDelegateProxyEnabled</key>
    <false />
Accepted Answer

your functions signatures are wrong. For example, if you use this it works:

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
        print("\n-------> applicationDidFinishLaunching")
        return true
    }
UIApplicationDelegateAdaptor won't do anything
 
 
Q