skip to Main Content

I have an issue with access to Firebase Firestore from my MacOs Application (SwiftUI).
All requirements are provided by my app like:

  • google.plist (bundle id, Firestore url etc are correct)
  • keychain access
  • incoming and outgoing connections

but stil when I try to setValue to my Firestore database I receive an error like so:

10.19.0 – [FirebaseDatabase][I-RDB034005] Firebase Database connection was forcefully killed by the server. Will not attempt reconnect. Reason: Firebase error. Please ensure that you have the URL of your Firebase Realtime Database instance configured correctly.

code to add a simple value looks like that:

Database.database().reference().child("test").setValue(["test": 123])

The method to initiate Firebase is located in AppDelegate:

final class AppDelegate: NSObject,  NSApplicationDelegate {
    func applicationDidFinishLaunching(_ notification: Notification) {
        UserDefaults.standard.register(defaults: ["NSApplicationCrashOnExceptions" : true])
        FirebaseApp.configure()
    }
}

do you have any idea what is missing here?

2

Answers


  1. The code:

    Database.database().reference().child("test").setValue(["test": 123])
    

    is for Firebase Realtime Database (RTDB), not Firestore.

    The error message is likely due to the fact that you have not initialized the RTDB service in your project…but if you are trying to use Firestore then don’t use RTDB code nor its service.

    Login or Signup to reply.
  2. First of all the code you are using it is not firestore . it is for firebase realtime database .

    to solve the error try this code for initialization DB

    import Firebase
    import FirebaseFirestore
    
    
    let db = Firestore.firestore()
    
    
    var ref: DocumentReference? = nil
    ref = db.collection("test").addDocument(data: [
        "test": 123
    ]) { err in
        if let err = err {
            print("Error adding document: (err)")
        } else {
            print("Document added with ID: (ref!.documentID)")
        }
    }
    

    hope it helps .

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search