【问题标题】:iOS 13 app requests a new scene each time the app icon is tapped每次点击应用图标时,iOS 13 应用都会请求一个新场景
【发布时间】:2020-01-04 02:58:36
【问题描述】:

我正在为我的应用设置多个窗口。它运作良好。但是当我从跳板打开我的应用程序时,它每次都会创建一个新窗口。

我正在使用最新的 Xcode 和 iPadOS 13.0 测试版。我所有的视图控制器、视图等都是以编程方式制作的。我唯一的故事板是 LaunchScreen。

Info.plist

<key>UIApplicationSceneManifest</key>
    <dict>
        <key>UIApplicationSupportsMultipleScenes</key>
        <true/>
        <key>UISceneConfigurations</key>
        <dict>
            <key>UIWindowSceneSessionRoleApplication</key>
            <array>
                <dict>
                    <key>UISceneConfigurationName</key>
                    <string>Default</string>
                    <key>UISceneDelegateClassName</key>
                    <string>ComicReader.SceneDelegate</string>
                </dict>
            </array>
        </dict>
    </dict>

AppDelegate.swift

func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
    UISceneConfiguration(name: "Default", sessionRole: connectingSceneSession.role)
}

SceneDelegate.swift

class SceneDelegate: UIResponder, UIWindowSceneDelegate {
    var window: UIWindow?

    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        guard let scene = scene as? UIWindowScene else { return }

        window = UIWindow(windowScene: scene)
        window?.rootViewController = DelegateHelper.rootViewController()
        window?.makeKeyAndVisible()
    }
}

在Apple的Gallery示例中,如果打开应用程序,滑动到主屏幕,然后再次打开应用程序,我就回到了原来的位置,没有再次调用scene(_:willConnectTo)。在我自己的应用程序中,每次打开应用程序时都会调用scene(_:willConnectTo),并且设置断点表明我确实在每次启动时收到了不同的 UIScene 和 UISceneSession 对象。

我没有显示任何 NSUserActivity 代码,因为我首先是因为我还没有任何状态恢复。实现它不会改变任何事情。

如果您有一些想法,我很乐意阅读!

【问题讨论】:

    标签: ios swift ios13 ipados uiscene


    【解决方案1】:

    所以,我从上周开始就在寻找这个。今天,我决定评论我所有的 AppDelegate、SceneDelegate,并在 Info.plist 中只保留一个场景配置。从默认模板重写 AppDelegate 和 SceneDelegate 以逐步挖掘。

    首次尝试使用默认模板即可。我重写了所有相同的东西……仍然有效。

    问题? UIWindowSceneSessionRoleApplication 数组中 Info.plist 中的“默认”配置是“项目 1”,而不是“项目 0”。 git stash 一切,只重新排序使它也能工作。

    我希望这对某人有所帮助。

    【讨论】:

      猜你喜欢
      • 2018-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-25
      • 1970-01-01
      相关资源
      最近更新 更多