尝试以编程方式 在AppDelegate的didFinishLaunchingWithOptions(..)函数中设置初始视图控制器-遵循答案here和here,但是遇到调试时的问题而不是显示“主页” VC,而是加载黑屏。我试图寻找其他人遇到的“黑屏”问题的答案,但是没有运气。
这是我的AppDelegate的didFinishLaunchingWithOptions:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
FirebaseApp.configure()
ApplicationDelegate.shared.application(application, didFinishLaunchingWithOptions: launchOptions)
let frame = UIScreen.main.bounds
let window = UIWindow(frame: frame)
let storyBoard : UIStoryboard = UIStoryboard(name: "Home", bundle: nil)
let homeVC = storyBoard.instantiateViewController(identifier: "Home")
window.rootViewController = homeVC
window.makeKeyAndVisible()
return true
}
“家庭”情节提要中的“家庭” VC已禁用/未选中“是初始视图控制器”。
在“常规”设置的“部署信息”部分下,我的项目的“主界面”为空。
我可以看到我的“ Home” VC的viewDidLoad()覆盖功能一直加载-但是,在产生黑屏之前,情节提要板本身并未加载(为白色)。
有帮助吗?不知道还有什么相关。
// Home.swift:
import Foundation
import UIKit
import Firebase
class Home: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
print("Something!")
self.view.backgroundColor = .green
}
}
控制台输出:
<Warning>: Please set a value for FacebookAutoLogAppEventsEnabled. Set the flag to TRUE if you want to collect app install, app launch and in-app purchase events automatically. To request user consent before collecting data, set the flag value to FALSE, then change to TRUE once user consent is received. Learn more: https://developers.facebook.com/docs/app-events/getting-started-app-events-ios#disable-auto-events.
<Warning>: You haven't set a value for FacebookAdvertiserIDCollectionEnabled. Set the flag to TRUE if you want to collect Advertiser ID for better advertising and analytics results. To request user consent before collecting data, set the flag value to FALSE, then change to TRUE once user consent is received. Learn more: https://developers.facebook.com/docs/app-events/getting-started-app-events-ios#disable-auto-events.
- <AppMeasurement>[I-ACS036002] Analytics screen reporting is enabled. Call +[FIRAnalytics setScreenName:setScreenClass:] to set the screen name or override the default screen class name. To disable screen reporting, set the flag FirebaseScreenReportingEnabled to NO (boolean) in the Info.plist
6.10.0 - [Firebase/Analytics][I-ACS023007] Analytics v.60103000 started
6.10.0 - [Firebase/Analytics][I-ACS023008] To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see ..)
FBSDKLog: Unable to find a valid UIWindow
Something!
[WindowScene] Failed to instantiate the default view controller for UIMainStoryboardFile 'Main' - perhaps the designated entry point is not set?
Unbalanced calls to begin/end appearance transitions for <ProjectName.Home: 0x7ffa2640ff90>.
进行澄清:
尝试以编程方式设置初始VC的重点是可以设置任何 VC。这在以下情况下很有用:应用程序最初加载时,检查用户是否已登录以及根据令牌显示相应屏幕的情况。
尝试避免使用中间VC进行转发,因为在iOS 13中,窗口顺序是分层的。
谢谢大家!
答案 0 :(得分:1)
在您的AppDelegate中 应该是
window = UIWindow(frame: frame)
代替
let window = UIWindow(frame: frame)