SwiftUI For Dummies. Wei-Meng Lee
This function is called whenever your app is needed to supply a new scene. Here, it returns the default item in the dictionary named Default Configuration: func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { // Called when a new scene session is being //created. Use this method to select a //configuration to create the new scene with. return UISceneConfiguration( name: "Default Configuration", sessionRole: connectingSceneSession.role)} A scene is an object that represents one instance of your app's user interface.
application(:didDiscardSceneSessions:): This function is called whenever a user discards a scene (such as swiping it away in the multitasking window).
SceneDelegate.swift
Whereas the AppDelegate.swift
file is responsible for handling your app life cycle, the SceneDelegate.swift
file is responsible for your scene's life cycle.
The SceneDelegate.swift
file contains the following default functions:
scene(_:willConnectTo:options:)
sceneDidDisconnect(_:)
sceneDidBecomeActive(_:)
sceneWillResignActive(_:)
sceneWillEnterForeground(_:)
sceneDidEnterBackground(_:)
The scene(_:willConnectTo:options:)
function is called when a scene is added to the app (in simple terms, when your UI is shown). Here, you load the content of the file named ContentView
(which is what you've modified earlier in the ContentView.swift
file):
func scene(_ scene: UIScene, willConnectTo session:
UISceneSession, options connectionOptions:
UIScene.ConnectionOptions) {
let contentView = ContentView()
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene:
windowScene)
window.rootViewController =
UIHostingController(rootView: contentView)
self.window = window
window.makeKeyAndVisible()
}
}
In short, you use AppDelegate.swift
to perform setup needed for the duration of the app. You also use it to handle events that focus on the app, as well as registered for external services like push notifications. The SceneDelegate.swift
, on the other hand, is designed to handle events for multi-window OS (iPadOS), which supports multiple instances of your app’s UI.
Конец ознакомительного фрагмента.
Текст предоставлен ООО «ЛитРес».
Прочитайте эту книгу целиком, купив полную легальную версию на ЛитРес.
Безопасно оплатить книгу можно банковской картой Visa, MasterCard, Maestro, со счета мобильного телефона, с платежного терминала, в салоне МТС или Связной, через PayPal, WebMoney, Яндекс.Деньги, QIWI Кошелек, бонусными картами или другим удобным Вам способом.