当我编写FirebaseApp.configure()时,iOS应用程序崩溃

当我编写FirebaseApp.configure()时,iOS应用程序崩溃,ios,swift,facebook,firebase,fbsdk,Ios,Swift,Facebook,Firebase,Fbsdk,我有一个ios应用程序,可以正常登录和facebook登录。今天我集成了firebase,当我在app delegate中编写FirebaseApp.configure()时,我的应用程序崩溃,此函数突出显示错误代码“在展开可选值时意外发现零”: AppDelegate类的代码为: // // AppDelegate.swift // // // Created by Macbook on 01/01/2018. // Copyright © 2018 Macbo0k. All rig

我有一个ios应用程序,可以正常登录和facebook登录。今天我集成了firebase,当我在app delegate中编写FirebaseApp.configure()时,我的应用程序崩溃,此函数突出显示错误代码“在展开可选值时意外发现零”:

AppDelegate类的代码为:

//
//  AppDelegate.swift
//  
//
//  Created by Macbook on 01/01/2018.
//  Copyright © 2018 Macbo0k. All rights reserved.
//

import UIKit
import IQKeyboardManagerSwift
import FBSDKCoreKit
import FBSDKLoginKit
import Firebase
import UserNotifications
import FirebaseInstanceID
import FirebaseMessaging

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        let usd = UserDefaults.standard


        if usd.object(forKey: "loginstatus") != nil && (usd.value(forKey: "loginstatus") != nil)  {
            if usd.value(forKey: "loginstatus") as! Bool != false{
                self.window = UIWindow(frame: UIScreen.main.bounds)

                let storyboard = UIStoryboard(name: "Main", bundle: nil)

                let initialViewController = storyboard.instantiateViewController(withIdentifier: "tabbarvc")

                self.window?.rootViewController = initialViewController
                self.window?.makeKeyAndVisible()
            }


        }
        FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)



        let newFont = UIFont(name: "BebasNeueLight", size: 20.0)!
        let color = UIColor(red: 255,green:204, blue:102)

        UINavigationBar.appearance().titleTextAttributes = [NSAttributedStringKey.foregroundColor: color,
                                                            NSAttributedStringKey.font: UIFont(name: "BebasNeueRegular", size: 20)!
        ]



        UIBarButtonItem.appearance(whenContainedInInstancesOf: [UINavigationBar.classForCoder() as! UIAppearanceContainer.Type]).setTitleTextAttributes([NSAttributedStringKey.foregroundColor: color, NSAttributedStringKey.font: newFont], for: .normal)
        UIBarButtonItem.appearance(whenContainedInInstancesOf: [UINavigationBar.classForCoder() as! UIAppearanceContainer.Type]).setTitleTextAttributes([NSAttributedStringKey.foregroundColor: color, NSAttributedStringKey.font: newFont], for: .highlighted)

        //print("fonts are: \(UIFont.familyNames)")
        IQKeyboardManager.sharedManager().enable = true

        FirebaseApp.configure()
        return true
    }

    func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {

        let isFacebookURL = url.scheme != nil && url.scheme!.hasPrefix("fb\(FBSDKSettings.appID())") && url.host == "authorize"
        if isFacebookURL {
            return FBSDKApplicationDelegate.sharedInstance().application(application, open: url as URL!, sourceApplication: sourceApplication, annotation: annotation)
        }
        return false
    }

    func applicationWillResignActive(_ application: UIApplication) {

    }

    func applicationDidEnterBackground(_ application: UIApplication) {
        print("app is in background mode")
    }

    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.
        FBSDKAppEvents.activateApp()

    }

    func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool {
        return FBSDKApplicationDelegate.sharedInstance().application(app, open: url, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String, annotation: options[UIApplicationOpenURLOptionsKey.annotation])

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


}
日志为:

2018-02-13 14:50:30.070051+0500 Sneakersapp[11075:119374] [MC] Reading from private effective user settings.
2018-02-13 14:50:30.113172+0500 Sneakersapp[11075:119374] Could not successfully update network info during initialization.
2018-02-13 14:50:30.824700+0500 Sneakersapp[11075:119470] TIC TCP Conn Failed [6:0x600000169480]: 12:8 Err(-65554)
2018-02-13 14:50:30.827309+0500 Sneakersapp[11075:119444] Task <D3E060F1-6F56-451A-B00C-CD3CFF86CD8F>.<2> HTTP load failed (error code: -1003 [12:8])
2018-02-13 14:50:30.827738+0500 Sneakersapp[11075:119444] Task <D3E060F1-6F56-451A-B00C-CD3CFF86CD8F>.<2> finished with error - code: -1003
2018-02-13 14:50:31.064485+0500 Sneakersapp[11075:119470] TIC Read Status [3:0x0]: 1:57
2018-02-13 14:50:31.064751+0500 Sneakersapp[11075:119470] TIC Read Status [3:0x0]: 1:57
2018-02-13 14:50:31.198410+0500 Sneakersapp[11075:119444] TIC Read Status [1:0x0]: 1:57
2018-02-13 14:50:31.199036+0500 Sneakersapp[11075:119444] TIC Read Status [1:0x0]: 1:57
2018-02-13 14:50:31.808151+0500 Sneakersapp[11075:119469] TIC Read Status [4:0x0]: 1:57
2018-02-13 14:50:31.808292+0500 Sneakersapp[11075:119469] TIC Read Status [4:0x0]: 1:57
(lldb) 
2018-02-13 14:50:30.070051+0500 SneakerApp[11075:119374][MC]从私人有效用户设置读取。
2018-02-13 14:50:30.113172+0500 SneakerApp[11075:119374]无法在初始化期间成功更新网络信息。
2018-02-13 14:50:30.824700+0500 SneakerApp[11075:119470]TIC TCP连接失败[6:0x600000169480]:12:8错误(-65554)
2018-02-13 14:50:30.827309+0500 SneakerApp[11075:119444]任务。HTTP加载失败(错误代码:-1003[12:8])
2018-02-13 14:50:30.827738+0500 SneakerApp[11075:119444]任务。已完成,但出现错误-代码:-1003
2018-02-13 14:50:31.064485+0500 SneakerApp[11075:119470]TIC读取状态[3:0x0]:1:57
2018-02-13 14:50:31.064751+0500 SneakerApp[11075:119470]TIC读取状态[3:0x0]:1:57
2018-02-13 14:50:31.198410+0500 SneakerApp[11075:119444]TIC读取状态[1:0x0]:1:57
2018-02-13 14:50:31.199036+0500 SneakerApp[11075:119444]TIC读取状态[1:0x0]:1:57
2018-02-13 14:50:31.808151+0500 SneakerApp[11075:119469]TIC读取状态[4:0x0]:1:57
2018-02-13 14:50:31.808292+0500 SneakerApp[11075:119469]TIC读取状态[4:0x0]:1:57
(lldb)
一旦我对didfinishLaunchingWithOptions函数中的FirebaseApp.configure()进行注释,应用程序就可以正常工作


请帮助。

我知道现在回答这个问题可能已经太晚了,但我也遇到了同样的问题,并注意到我忘了在应用程序的主目录上导入GoogleService-Info.plist。

如果您没有正确配置Firebase应用程序,就会发生此崩溃

你在Firebase上注册过你的项目吗? 请浏览以下连结:-


在项目设置中,向firebase注册应用程序后,您将收到一个谷歌信息plist。下载它并将其导入到您的项目中

尝试添加异常断点并查找应用程序实际崩溃的位置…可能需要在方法顶部编写Firebase.configure()语句。您能更详细地描述您的解决方案吗?谢谢。如果你看一下最后一步是“从Firebase控制台下载GoogleService-Info.plist文件并将其包含在你的应用程序中。注意:如果你的项目中有多个捆绑ID,那么每个捆绑ID都必须在Firebase控制台中连接,这样它就可以拥有自己的GoogleService-Info.plist文件。”因此,基本上,您不应该忘记在项目中放置正确的plist文件。
2018-02-13 14:50:30.070051+0500 Sneakersapp[11075:119374] [MC] Reading from private effective user settings.
2018-02-13 14:50:30.113172+0500 Sneakersapp[11075:119374] Could not successfully update network info during initialization.
2018-02-13 14:50:30.824700+0500 Sneakersapp[11075:119470] TIC TCP Conn Failed [6:0x600000169480]: 12:8 Err(-65554)
2018-02-13 14:50:30.827309+0500 Sneakersapp[11075:119444] Task <D3E060F1-6F56-451A-B00C-CD3CFF86CD8F>.<2> HTTP load failed (error code: -1003 [12:8])
2018-02-13 14:50:30.827738+0500 Sneakersapp[11075:119444] Task <D3E060F1-6F56-451A-B00C-CD3CFF86CD8F>.<2> finished with error - code: -1003
2018-02-13 14:50:31.064485+0500 Sneakersapp[11075:119470] TIC Read Status [3:0x0]: 1:57
2018-02-13 14:50:31.064751+0500 Sneakersapp[11075:119470] TIC Read Status [3:0x0]: 1:57
2018-02-13 14:50:31.198410+0500 Sneakersapp[11075:119444] TIC Read Status [1:0x0]: 1:57
2018-02-13 14:50:31.199036+0500 Sneakersapp[11075:119444] TIC Read Status [1:0x0]: 1:57
2018-02-13 14:50:31.808151+0500 Sneakersapp[11075:119469] TIC Read Status [4:0x0]: 1:57
2018-02-13 14:50:31.808292+0500 Sneakersapp[11075:119469] TIC Read Status [4:0x0]: 1:57
(lldb)