首页 > 解决方案 > 获取线程:信号 SIGABRT

问题描述

构建具有聊天功能的应用程序并收到 SIGBRT 错误。它似乎没有与 Firebase 数据库对话。我检查了我所有的插座,它们似乎都完好无损,我没有看到任何破损的插座。

我在调试区域遇到的错误是

“2018-08-21 01:09:15.479487-0400 拆分应用程序 [83668:9375919] *** 由于未捕获的异常“FIRAppNotConfigured”而终止应用程序,原因:“无法获取默认 Firebase 数据库实例。必须调用[FIRApp configure]FirebaseApp.configure()在 Swift 中)在使用 Firebase 数据库之前...... libc++abi.dylib:以 NSException 类型的未捕获异常终止”

class DataService{
static let dataService = DataService()
private var _BASE_REF = Database.database().reference()
private var _ROOM_REF = Database.database().reference().child("rooms")
var BASE_REF: DatabaseReference {
   return _BASE_REF
}
var ROOM_REF:DatabaseReference{
    return _ROOM_REF
}
var storageRef: StorageReference{
    return Storage.storage().reference()
}
var fileURL: String!
// store the thumbnail in database
func CreateNewRoom(user: User, caption: String, data: NSData){
    let filePath = "\(user.uid)/\   
(Int(NSDate.timeIntervalSinceReferenceDate))"

    let metaData = StorageMetadata()
    metaData.contentType = "image/jpg"
    storageRef.child(filePath).putData(data as Data, metadata: metaData){ 
(metadata, error) in if error != nil {
        print ("Error Uploading: \(String(describing: 
error?.localizedDescription))")
        return
        }
        //create a url for data (photo thumbnail image)
          _ = metadata?.storageReference?.downloadURL(completion: error as! 
(URL?, Error?) -> Void)
        if Auth.auth().currentUser != nil {
            let idRoom = self.BASE_REF.child("rooms").childByAutoId()
            idRoom.setValue(["caption": caption,"thumbnailURLFromStorage": 
self.storageRef.child(metadata!.path!).description, "fileURL" : 
self.fileURL])
        }
    }
}

func fetchDataFromServer(callback: @escaping (Room) -> ()){
    DataService.dataService.ROOM_REF.observe(.childAdded){ (snapshot) in
        let room = Room(key: snapshot.key, snapshot: snapshot.value as! 
Dictionary<String, Any>)
     callback(room)
    }
}
func SignUp(username:String, email: String, password: String, firstName: 
String, lastName: String, data: NSData){
    Auth.auth().createUser(withEmail: email, password: password, completion: 
{ (user, error) in
        if  error != nil {
            print(error!)
        }
        else {
            print("Registration Successful")
        }
        let changeRequest = 
Auth.auth().currentUser?.createProfileChangeRequest()
        changeRequest?.displayName = username
        changeRequest?.commitChanges(completion: {(error) in
            if let error = error {
                print (error.localizedDescription)
                return
            }
        })
        let filePath = "profileimage/\(String(describing: 
Auth.auth().currentUser!.uid))"
        let metadata = FirebaseStorage.StorageMetadata()
        metadata.contentType = "image/jpeg"

        self.storageRef.child(filePath).putData(data as Data, metadata:  
metadata, completion: {(metadata, error) in

        if let error = error {
            print ("\(error.localizedDescription)")
            return
        }
            _ = metadata?.storageReference?.downloadURL(completion: error as! 
(URL?, Error?) -> Void)
            if let error = error {
                print (error.localizedDescription)
                return
            }
            else {
                print ("Sweet!")
            }
        let appDelegate: AppDelegate = UIApplication.shared.delegate as! 
AppDelegate
        appDelegate.login()

    })
    }
}

标签: swiftfirebasefirebase-realtime-databasesigabrtnsexception

解决方案


你应该按照这些步骤

第 1 步将 Firebase 导入您的 AppDelegate.swift

import Firebase

步骤 2在 AppDelegate.swift 中的 didFinishLaunchingWithOptions 方法中调用 configure()

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    FirebaseApp.configure()
    return true
}

希望能帮助到你


推荐阅读