问题:
我发现有关 AppDelegate 方法的一些意外行为application(_:configurationForConnecting:options:)
。
该文档指出:
UIKit 在创建新场景之前不久调用此方法。
我希望每次启动应用程序时都是这种情况。
当我第一次启动我的应用程序时确实调用了该方法,但是对于所有后续启动,它不是.
复制:
我有一个非常简单的测试用例可以重现:
- Xcode 12 > 创建新项目 > iOS > App (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 的错误)