为啥我在设备或模拟器上运行我的应用程序时屏幕是黑色的
Posted
技术标签:
【中文标题】为啥我在设备或模拟器上运行我的应用程序时屏幕是黑色的【英文标题】:Why does the screen be Black when I run my app on a device or in simulator为什么我在设备或模拟器上运行我的应用程序时屏幕是黑色的 【发布时间】:2017-07-27 19:36:43 【问题描述】:当我在设备或 ios 模拟器上运行我的应用程序时,我需要一些帮助来尝试解决问题,但如果我按下主页按钮然后点击应用程序,它会显示所有内容.有谁知道实际发生了什么?
Picture Of Simulator via Black Screen
导入 UIKit 导入 Firebase 导入用户通知 导入 FirebaseInstanceID 导入 FirebaseMessaging
@UIApplicationMain 类 AppDelegate: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:.
【问题讨论】:
发布您的 AppDelegate didFinishLaunchingWithOptions 方法。您的应用实际上已经在运行,但您并未处理其后台前台状态 投票赞成关闭,因为问题过于广泛且不清楚,无法正确回答 【参考方案1】:在没有看到您的代码的情况下,我有 2 个解决方案,它们当然非常广泛:
-
我猜你的项目没有很多东西。最好的办法就是从头开始重做。很确定你犯了一些你无法真正发现的小错误,而我们也不能在没有看到你的代码的情况下发现。
回想一下你做了什么,它变成了这样(显示黑屏)并恢复你的代码,看看是什么真正造成了这个黑屏。
【讨论】:
【参考方案2】:我认为您的 rootviewcontoller 视图是两个链接视图,因此删除所有和其他文本字段并删除 UIlabel。然后运行应用程序。
//remove Newview in this picture
我认为第二种解决方案是设置 rootviewcontoler 以编程方式。
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
if let rvc = self.window?.rootViewController
self.window!.rootViewController = rvc.storyboard!.instantiateViewControllerWithIdentifier("rootviewcontoller")
return true
【讨论】:
【参考方案3】:我遇到了同样的问题。阅读控制台日志后,我意识到 GoogleService-Info.plist
没有添加到 Xcode 中的项目中,即使我将文件复制并放入项目目录中。为了解决这个问题,手动将GoogleService-Info.plist
添加到Xcode中。单击File
-> Add File to project
并选择文件。再次运行项目,问题应该得到解决。编码愉快!
【讨论】:
以上是关于为啥我在设备或模拟器上运行我的应用程序时屏幕是黑色的的主要内容,如果未能解决你的问题,请参考以下文章
iPhone模拟器中的白色空白屏幕和加载到iPhone时的黑色空白屏幕