gpt4 book ai didi

ios - 无法摆脱致命异常 : NSInternalInconsistencyException Error

转载 作者:行者123 更新时间:2023-12-02 07:06:32 24 4
gpt4 key购买 nike

Fatal Exception: NSInternalInconsistencyExceptionApplication windows are expected to have a root view controller at the end of application launch-[UIApplication _runWithMainScene:transitionContext:completion:]

Crash Report

Fatal Exception: NSInternalInconsistencyException    0  ???                            0x184066d8c (Missing)    1  ???                            0x1832205ec (Missing)    2  ???                            0x184066bf8 (Missing)    3  ???                            0x184a56fa0 (Missing)    4  UIKit                          0x18dc42a80 -[UIApplication _runWithMainScene:transitionContext:completion:]    5  UIKit                          0x18e272b1c __111-[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:]_block_invoke    6  UIKit                          0x18dc41dd0 +[_UICanvas _enqueuePostSettingUpdateTransactionBlock:]    7  UIKit                          0x18dc41c6c -[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:]    8  UIKit                          0x18dc40afc -[__UICanvasLifecycleMonitor_Compatability activateEventsOnly:withContext:completion:]    9  UIKit                          0x18e8d684c __82-[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:]_block_invoke    10 UIKit                          0x18dc401ec -[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:]    11 UIKit                          0x18e6bbac8 __125-[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:]_block_invoke    12 UIKit                          0x18e809bf8 _performActionsWithDelayForTransitionContext    13 UIKit                          0x18dc3fc0c -[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:]    14 UIKit                          0x18dc3f5a8 -[_UICanvas scene:didUpdateWithDiff:transitionContext:completion:]    15 UIKit                          0x18dc3c5e0 -[UIApplication workspace:didCreateScene:withTransitionContext:completion:]    16 UIKit                          0x18dc3c330 -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:]

Crash report header is

UIKit
-[UIApplication _runWithMainScene:transitionContext:completion:]

applicationDidFinishLaunching

if (launchOptions == nil) {
if (TegKeychain.get("ISLOGGEDIN") == "1") {
heartbeat()
let initialViewController = storyboard.instantiateViewController(withIdentifier: "WelcomeTab")
self.window?.rootViewController = initialViewController
self.window?.makeKeyAndVisible()
} else {
let initialViewController = storyboard.instantiateViewController(withIdentifier: "Entrance")
self.window?.rootViewController = initialViewController
self.window?.makeKeyAndVisible()
}
} else {
if let notifications = launchOptions?[UIApplicationLaunchOptionsKey.remoteNotification] as? [String: AnyObject] {
heartbeat()

if let type = notifications["type"] as? String
{
if type == "msg" {
if let userID = notifications["userID"] as? String {
userDefaults.set(userID, forKey: "goToChat")
}

let initialViewController = storyboard.instantiateViewController(withIdentifier: "WelcomeTab")
self.window?.rootViewController = initialViewController
self.window?.makeKeyAndVisible()

if let tabBarController = self.window!.rootViewController as? UITabBarController {
tabBarController.selectedIndex = 3
}
}

if type == "follow" {
if let userID = notifications["userID"] as? String {
userDefaults.set(userID, forKey: "goToProfile")
}
let initialViewController = storyboard.instantiateViewController(withIdentifier: "WelcomeTab")
self.window?.rootViewController = initialViewController
self.window?.makeKeyAndVisible()

if let tabBarController = self.window!.rootViewController as? UITabBarController {
tabBarController.selectedIndex = 0
}
}

if type == "attend" {
if let eventID = notifications["eventID"] as? String {
userDefaults.set(eventID, forKey: "goToEvent")
}
let initialViewController = storyboard.instantiateViewController(withIdentifier: "WelcomeTab")
self.window?.rootViewController = initialViewController
self.window?.makeKeyAndVisible()

if let tabBarController = self.window!.rootViewController as? UITabBarController {
tabBarController.selectedIndex = 0
}
}
}
}

if let _ = launchOptions?[UIApplicationLaunchOptionsKey.location] {
startSignificationLocation()
}
}

那是什么崩溃以及如何摆脱它?

最佳答案

applicationDidFinishLaunching 完成之前,您的应用程序委托(delegate)未设置主 UIWindow 的 rootViewController 属性。这通常是在所有 Xcode 模板中为您设置的。如果您创建自己的窗口,请确保立即设置其 Root View Controller 。

正如 rmaddy 所指出的,在您的代码中,如果设置了 launchOptions,但 launchOptions?[UIApplicationLaunchOptionsKey.remoteNotification] as? [String: AnyObject] 返回 nil,则永远不会设置 rootViewController。如果 notifications["type"] 为? String 为零,rootViewController 从未设置。如果类型不是您期望的三个值,则永远不会设置 rootViewController

rootViewController 必须在此方法完成之前设置,否则应用程序将崩溃。您需要涵盖应用程序启动的所有可能方式。没有 promise 列出应用程序可以启动的所有可能方式,因此当它以您不期望的方式启动时,您将需要某种后备(否则“应用程序崩溃”就是您的行为)在这种情况下重新请求)。

关于ios - 无法摆脱致命异常 : NSInternalInconsistencyException Error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52260986/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com