【发布时间】:2020-12-10 16:07:29
【问题描述】:
问题:
我发现有关 AppDelegate 方法 application(_:configurationForConnecting:options:) 的一些意外行为。
文档说明:
UIKit 在创建新场景前不久调用此方法。
我希望每次启动应用程序时都会出现这种情况。
当我第一次启动我的应用程序时确实调用了该方法,但是对于所有后续启动,它不是。
转载:
我有一个非常简单的测试用例要重现:
- Xcode 12 > 创建新项目 > iOS > 应用程序(UIKit/Storyboard)
- 在
AppDelegate的方法中添加调试语句,如下所示:// from Apple's sample project: 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. print("I was called!"). // <--- debugging statement return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) } - 运行应用程序>“我被召唤了!”在控制台中打印
- 再次运行应用程序 > 没有打印任何内容。
问题:
为什么application(_:configurationForConnecting:options:) 在第二次启动时没有被调用?
(这是预期的行为,如果是,为什么/它是 Apple 的错误)
【问题讨论】:
标签: ios swift appdelegate xcode12 uiscenedelegate