我們將應用從 SwiftUI 遷移到 UIKit 生命周期和應用包含,創建標準 AppDelegate、SceneDelegate,并更新所需的 info.plist 屬性。我沒有遵循本教程,但如果您不熟悉,這正是我們所做的。https://mokacoding.com/blog/how-to-migrate-from-swiftui-to-uikit-life-cycle/。
我們的問題是物理 iPhone 設備安裝了 SwiftUI 生命周期的應用程式、黑屏并且在啟動時沒有回應。除錯證明這是因為SceneDelegate根本沒有呼叫 setup 函式。iPhone模擬器,構建到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>
uj5u.com熱心網友回復:
嘗試從中洗掉場景配置清單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
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/496744.html
