0

Building an app with a chat feature and getting a SIGBRT error. It doesn't seem to be talking to the Firebase database. I checked all my outlets and they seem to all be intact and I didn't see any broken outlets.

the error I'm getting in the debug area is

"2018-08-21 01:09:15.479487-0400 Split App[83668:9375919] *** Terminating app due to uncaught exception 'FIRAppNotConfigured', reason: 'Failed to get default Firebase Database instance. Must call [FIRApp configure] (FirebaseApp.configure() in Swift) before using Firebase Database.... libc++abi.dylib: terminating with uncaught exception of type 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()

    })
    }
}
ReyAnthonyRenacia
  • 17,219
  • 5
  • 37
  • 56
  • 1
    Please **read** the error message. *Must call [FIRApp configure] (FirebaseApp.configure() in Swift) before using Firebase Database* is highly descriptive. It doesn't say anything about outlets. – vadian Aug 21 '18 at 06:09

2 Answers2

0

You should follow these steps

Step 1 Import Firebase to your AppDelegate.swift

import Firebase

Step 2 call configure() in didFinishLaunchingWithOptions method in AppDelegate.swift

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

Hope it helps

Bhavin Kansagara
  • 2,866
  • 1
  • 16
  • 20
0

You have not configured firebase yet . So just inside you app delegate first import Firebase and inside the method didFinishLaunchingWithOptions configure firebase. By writing a single line FirebaseApp.configure().

Enea Dume
  • 3,014
  • 3
  • 21
  • 36
kchopda
  • 312
  • 4
  • 16