当我 运行 我的应用程序在设备或模拟器中时,为什么屏幕是黑色的

Why does the screen be Black when I run my app on a device or in simulator

当我 运行 我的应用程序在设备上或在 iOS 模拟器中时,我需要一些帮助来解决它显示黑屏的问题,但如果我按下主页按钮然后点击它显示所有内容的应用程序。有谁知道实际发生了什么?

Picture Of Simulator via Black Screen

导入 UIKit 导入 Firebase 导入用户通知 导入 FirebaseInstanceID 导入 FirebaseMessaging

@UIApplicationMain classAppDelegate:UIResponder、UIApplicationDelegate、UNUserNotificationCenterDelegate、FIRMessagingDelegate{

var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    FIRApp.configure()
    application.statusBarStyle = .lightContent

    if #available(iOS 10.0, *) {
        // For iOS 10 display notification (sent via APNS)
        UNUserNotificationCenter.current().delegate = self
        let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
        UNUserNotificationCenter.current().requestAuthorization(
            options: authOptions,
            completionHandler: {_, _ in })
        // For iOS 10 data message (sent via FCM
        FIRMessaging.messaging().remoteMessageDelegate = self
    } else {
        let settings: UIUserNotificationSettings =
            UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
        application.registerUserNotificationSettings(settings)
    }

    application.registerForRemoteNotifications()
     return true

}

func applicationReceivedRemoteMessage(_ remoteMessage: FIRMessagingRemoteMessage) {
    print(remoteMessage.appData)
}

func applicationWillResignActive(_ application: UIApplication) {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}

func applicationDidEnterBackground(_ application: UIApplication) {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(_ application: UIApplication) {
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(_ application: UIApplication) {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(_ application: UIApplication) {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

}

在没有看到你的代码的情况下,我有 2 个解决方案,它们当然非常广泛:

  1. 我猜你的项目没有很多东西。最好的办法就是从头开始重做。很确定你犯了一些你无法真正发现的小错误,我们也不能在没有看到你的代码的情况下发现。
  2. 回想一下你做了什么让它变成这样(显示黑屏)并还原你的代码,看看究竟是什么导致了这个黑屏。

我认为您的 rootviewcontroller 视图是两个 link 视图,因此删除所有和其他文本字段并删除 UIlabel。然后 运行 应用程序。

 //remove Newview in this picture

And I think the second solution is set rootviewcontoler programmatically.

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    if let rvc = self.window?.rootViewController {
             self.window!.rootViewController = rvc.storyboard!.instantiateViewControllerWithIdentifier("rootviewcontoller")     
        }
    return true
}

我遇到了同样的问题。阅读控制台日志后,我意识到 GoogleService-Info.plist 没有添加到 Xcode 中的项目,即使我复制文件并将其放入项目目录。要解决这个问题,请手动将GoogleService-Info.plist添加到Xcode中。单击 File -> Add File to project 和 select 文件。 运行 再次启动该项目,问题应该已解决。编码愉快!