App delegate methods aren't being called in iOS 13
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
App Delegate Methods Aren't Being Called in iOS 13
The introduction of iOS 13 brought a multitude of changes to Apple's mobile operating system, enhancing user experience and developer capabilities. However, with these advancements, some developers encountered issues with app delegate methods not being called as expected. This article delves into the reasons behind these issues, solutions, and best practices to adapt to the changes in iOS 13.
Background
The App Delegate is a cornerstone of an iOS app, acting as the central point of control and coordination. It responds to key app life cycle events such as app launch, state transitions, and notifications. Traditionally, these interactions are managed through methods provided by the `UIApplicationDelegate` protocol, such as:
- `application(_:didFinishLaunchingWithOptions:)`
- `applicationWillResignActive(_:)`
- `applicationDidEnterBackground(_:)`
- `applicationWillEnterForeground(_:)`
- `applicationDidBecomeActive(_:)`
- `applicationWillTerminate(_:)`
The Problem in iOS 13
In iOS 13, some developers observed that certain app delegate methods were not being called. This behavior is primarily due to the introduction of Scene Delegates and changes in the app life cycle management.
Scene Delegates: An Overview
iOS 13 introduced the concept of multi-window support on iPadOS and improved multitasking on iOS. To accommodate this, Apple introduced `UISceneDelegate`, offloading some responsibilities from the App Delegate to individual scene delegates. This change means that the app delegate no longer handles UI-related events; instead, scene delegates manage them.
Key methods moved to `UISceneDelegate` include:
- `scene(_:willConnectTo:options:)`
- `sceneDidDisconnect(_:)`
- `sceneDidBecomeActive(_:)`
- `sceneWillResignActive(_:)`
- `sceneWillEnterForeground(_:)`
- `sceneDidEnterBackground(_:)`
Adapting to Scene Delegate Architecture
Updating the Project
When creating a new project in Xcode targeting iOS 13 or later, Xcode initializes the template with both an App Delegate and a Scene Delegate. However, existing projects upgraded to iOS 13 may require manual adjustments.
Modifying the `Info.plist`
The presence of a scene delegate is indicated in the app’s `Info.plist` file:
Related reading
- App getting crash when click on GoogleSignIn button. Why?
- App getting crash when click on GoogleSignIn button. Why?
- App installation failed due to application-identifier entitlement
- ''App not Installed'' Error on Android
- App does not contain the correct beta entitlement
- App installation failed Could not write to the device
- App rejected due to missing usage descriptions Xcode8
- App Tracking Transparency How does effect apps showing ads? - IDFA iOS14
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.