代码之家  ›  专栏  ›  技术社区  ›  Oscar Apeland

迁移到UIKit生命周期的应用程序不调用SceneDelegate

  •  2
  • Oscar Apeland  · 技术社区  · 3 年前

    我们将应用程序从SwiftUI迁移到UIKit生命周期和应用程序容器中,创建了标准的AppDelegate、SceneDelegate,并更新了所需的信息。plist属性。我没有学习本教程,但如果您不熟悉,这也正是我们所做的。 https://mokacoding.com/blog/how-to-migrate-from-swiftui-to-uikit-life-cycle/ .

    我们的问题是,安装了具有SwiftUI生命周期的应用程序的物理iPhone设备出现黑屏,并且在发布时没有响应。调试证明,这是因为 SceneDelegate 永远不会调用设置函数。iPhone模拟器、building to Mac等工作正常。

    删除应用程序并重新安装可以解决此问题,但我们无法从我们的安装群中要求。

    是否有任何方法可以强制已安装的应用程序清除其缓存或控制启动配置的任何内容?

    这是相关代码。

    AppDelegate,正在调用此

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        return true
    }
    

    SceneDelegate,这不是呼叫

    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        guard let scene = scene as? UIWindowScene else { return }
    
        window = UIWindow(windowScene: scene)
        let viewController: UIViewController
        if isLoggedIn {
            viewController = MainViewController()
        } else {
            viewController = UIHostingController(
                rootView: LandingView().injectingEnvironment()
            )
        }
        window!.rootViewController = viewController
        window!.makeKeyAndVisible()
    }
    

    信息。普利斯特

    <key>UIApplicationSceneManifest</key>
    <dict>
        <key>UIApplicationSupportsMultipleScenes</key>
        <true/>
        <key>UISceneConfigurations</key>
        <dict>
            <key>UIWindowSceneSessionRoleApplication</key>
            <array>
                <dict>
                    <key>UISceneConfigurationName</key>
                    <string>Default Configuration</string>
                    <key>UISceneDelegateClassName</key>
                    <string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
                </dict>
            </array>
        </dict>
    </dict>
    
    1 回复  |  直到 3 年前
        1
  •  1
  •   Asperi    3 年前

    尝试从中删除场景配置清单 Info.plist 并在中以编程方式创建 AppDelegate 喜欢

    class AppDelegate: NSObject, UIApplicationDelegate {
    
    
        func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
            let configuration = UISceneConfiguration(name: nil, sessionRole: connectingSceneSession.role)
            if connectingSceneSession.role == .windowApplication {
                configuration.delegateClass = SceneDelegate.self
            }
            return configuration
        }
    }