Can you help me to understand why app still work if I delete default app delegate methods such as applicationWillResignActive
and applicationDidEnterBackground
?
In part, the declaration of the UIApplicationDelegate
protocol looks like this:
public protocol UIApplicationDelegate : NSObjectProtocol {
optional public func applicationDidFinishLaunching(_ application: UIApplication)
optional public func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool
optional public func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool
optional public func applicationDidBecomeActive(_ application: UIApplication)
optional public func applicationWillResignActive(_ application: UIApplication)
...
Note that the functions are declared as optional. This means that code that conforms to the protocol does not have to implement those functions.
If your app doesn't need to do anything special when it enters the background, then you don't need to implement applicationDidEnterBackground
. If your app did need to do something, then you would implement that function.