我们将应用程序从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等工作正常.

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

Is there any way to force installed apps to clear their cache or whatever it is that controls launch configurations?

这是相关代码.

AppDelegate, this is being called

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

SceneDelegate, this is NOT being called

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()
}

info.plist

<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>

推荐答案

try 从Info.plist中删除场景配置 list ,并在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
    }
}

Ios相关问答推荐

Swift:从字符串目录获取带有参数的本地化字符串

设置堆栈视图的所有属性

将数据传回VC时委托为空

Xcode -Google Mobile Ads SDK在没有AppMeasurement的情况下初始化

有没有办法将滚动视图RTL(阿拉伯语)与Ltr动画一起使用?

当文本为空时,具有垂直轴的SwiftUI文本字段不会与FirstTextBaseline对齐

swift|在具有自定义单元格的多个TableView中没有任何内容

如何为 Firebase Auth 实施 Firebase AppCheck?

具有线性渐变的 SVG textPath 在 Safari 中损坏

添加到单个自定义视图时,Swiftui 项目会在所有视图中重复

如何在 SwiftUI 的 TabView 中添加底部曲线?

无法结合 UIImageView 旋转动画和 tableView 部分重新加载

SignalR 永远不会在 iOS 上使用 Xamarin Forms 启动

构建失败:ld:重复符号 _OBJC_CLASS_$_Algebra5FirstViewController

使用 convertPoint 获取父 UIView 内的相对位置

在 iOS 上存储身份验证令牌 - NSUserDefaults 与 keys 串?

正确使用 Alamofire 的 URLRequestConvertible

我可以通过 UIAppearance 代理设置哪些属性?

用 NavigationViewController 快速呈现 ViewController

在转发类对象中找不到属性