gpt4 book ai didi

swift - iOS 13 : Cannot navigate conditionally to a different viewontroller from AppDelegate. swift

转载 作者:行者123 更新时间:2023-11-30 10:27:19 25 4
gpt4 key购买 nike

我已将登录 View Controller 设置为 Storyboard中的初始 Controller 。但是,当用户有事件 session 时,我想导航到应用程序的主视图 Controller 。这是我所拥有的:

func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let sessionToken = "abcedef"

let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)
if sessionToken != nil {
let tabBarVC = storyboard.instantiateViewController(identifier: "TabBarVC")
tabBarVC.modalPresentationStyle = .fullScreen
self.window?.rootViewController?.present(tabBarVC, animated: true, completion: nil)
}
return true
}

但我仍然看到登录页面。你知道我可能做错了什么吗?

最佳答案

SceneDelegate.swift

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, 
options connectionOptions: UIScene.ConnectionOptions) {

let windowScene = UIWindowScene(session: session, connectionOptions: connectionOptions)
self.window = UIWindow(windowScene: windowScene)

let sessionToken = "abcedef"

let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)
if sessionToken != nil {
let story = UIStoryboard(name: "Main", bundle:nil)
let vc = story.instantiateViewController(withIdentifier: "InitialController") as! InitialController

let rootNC = UINavigationController(rootViewController: vc) // As per need
rootNC.isNavigationBarHidden = true
self.window?.rootViewController = rootNC
self.window?.makeKeyAndVisible()
}
guard let _ = (scene as? UIWindowScene) else { return }

}

低于 iOS 13 AppDelegate.swift

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
self.initialRootVC()
return true
}

func initialRootVC() {
let story = UIStoryboard(name: "Main", bundle:nil)
let vc = story.instantiateViewController(withIdentifier: "InitialController") as! InitialController
let rootNC = UINavigationController(rootViewController: vc). // when require
rootNC.isNavigationBarHidden = true
self.window?.rootViewController = rootNC
self.window?.makeKeyAndVisible()
}

关于swift - iOS 13 : Cannot navigate conditionally to a different viewontroller from AppDelegate. swift ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59890683/

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