AppDelegate.swift 应用代理文件 -位于项目文件中,包含很多监听系统事件的方法,同时也定义了应用程序的一些生命周期方法
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
didFinishLaunchingWithOptions
方法是程序启动的入口,只有应用程序启动时执行一次。
开发者通常在该方法中进行应用程序的一些配置工作。
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)
}
*configurationForConnecting
在创建新的场景会话时,会调用此方法,可以用来选择用于创建新场景的配置。
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
// Called when the user discards a scene session.
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}
didDiscardSceneSessions
当用户放弃场景会话时,调用该方法。可以使用此方法释放被丢弃场景的资源,以节省系统开销。