应用程序未使用 AppDelegate 启动,didFinishLaunchingWithOptions() 永远不会被调用
App not launching with AppDelegate, didFinishLaunchingWithOptions() never gets called
我是 iOS 编程新手。我正在尝试制作我拥有的 Android 应用程序的 iOS 版本。
在一切正常之前,但后来我添加了一个 TabBarController 作为主 UIViewController,应用程序开始在其中启动 activity。
这是我的故事板:
This is my storyboard
AppDelegate 的 didFinishLaunchingWithOptions():
let tokenLogin: Bool = UserDefaults.standard.bool(forKey: "tokenLogin")
if !tokenLogin {
self.showLoginScreen()
}
所以这个想法是,如果用户从未登录过,就会出现登录屏幕,如果登录有效,标签栏 activity 就会启动。
现在,因为从未执行 AppDelegate,所以我无法让用户登录。
如有任何帮助,我们将不胜感激。
编辑:
我按照 DivyaS 的建议将 'Main Interface' 更改为空白。但是 didFinishLaunchingWithOptions()
仍然没有执行(我检查过这是该函数的最新版本)。我在一开始就打印了一张纸来检查,但什么也没有。屏幕只是黑色的。
您需要转到目标中的常规选项卡并向下滚动到 "Deployment Info",然后将主界面重置为空白。
然后在 AppDelegate.swift 中,您需要根据逻辑选择视图控制器。
示例:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
window = UIWindow.init(frame: UIScreen.main.bounds)
window?.backgroundColor = UIColor.white
if UserDefaults.sharedInstance.getIsUserLogin(){
// user has configured his profile and he is ready to use the app
// configure tab bar
let vc = TabBarViewController()
navigationController = UINavigationController.init(rootViewController: vc)
} else {
// user is not login
let vc = LoginViewController()
navigationController = UINavigationController.init(rootViewController: vc)
}
window?.rootViewController = navigationController
window?.makeKeyAndVisible()
return true
我是 iOS 编程新手。我正在尝试制作我拥有的 Android 应用程序的 iOS 版本。
在一切正常之前,但后来我添加了一个 TabBarController 作为主 UIViewController,应用程序开始在其中启动 activity。
这是我的故事板: This is my storyboard
AppDelegate 的 didFinishLaunchingWithOptions():
let tokenLogin: Bool = UserDefaults.standard.bool(forKey: "tokenLogin")
if !tokenLogin {
self.showLoginScreen()
}
所以这个想法是,如果用户从未登录过,就会出现登录屏幕,如果登录有效,标签栏 activity 就会启动。
现在,因为从未执行 AppDelegate,所以我无法让用户登录。
如有任何帮助,我们将不胜感激。
编辑:
我按照 DivyaS 的建议将 'Main Interface' 更改为空白。但是 didFinishLaunchingWithOptions()
仍然没有执行(我检查过这是该函数的最新版本)。我在一开始就打印了一张纸来检查,但什么也没有。屏幕只是黑色的。
您需要转到目标中的常规选项卡并向下滚动到 "Deployment Info",然后将主界面重置为空白。
然后在 AppDelegate.swift 中,您需要根据逻辑选择视图控制器。 示例:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
window = UIWindow.init(frame: UIScreen.main.bounds)
window?.backgroundColor = UIColor.white
if UserDefaults.sharedInstance.getIsUserLogin(){
// user has configured his profile and he is ready to use the app
// configure tab bar
let vc = TabBarViewController()
navigationController = UINavigationController.init(rootViewController: vc)
} else {
// user is not login
let vc = LoginViewController()
navigationController = UINavigationController.init(rootViewController: vc)
}
window?.rootViewController = navigationController
window?.makeKeyAndVisible()
return true