Home > database >  iOS: Firebase: Database lives in a different region. Where to put the link?
iOS: Firebase: Database lives in a different region. Where to put the link?

Time:02-17

I am new to SwiftUI and I am currently making my first ever Firebase app. (Xcode SwiftUI iOS 15.0) I have this problem. When I want to save messages to my Realtime Database, I get this error:

Firebase Database connection was forcefully killed by the server. Will not attempt reconnect. Reason: Database lives in a different region. Please change your database URL to "My Firebase URL"

(My database is already linked to this URL)

On other posts I saw this soloution:

let ref = Database.database(url: "My Firebase URL")

Where do I have to put this line of code? Thank you!

CodePudding user response:

You have to put that code wherever you are creating a reference to data from Firebase.

If you look at this code from step 3 of the Firebase documentation on setting up a connection to the database:

var ref: DatabaseReference!

ref = Database.database().reference()

This syntax creates a reference to the database as it is defined in your GoogleService-Info.plist file.

Since you want to specify the URL in your code, you'd do:

var ref: DatabaseReference!

ref = Database.database("your database URL").reference()

And then use ref everywhere else to read and write data.


You can alternatively also download an updated GoogleService-Info.plist file from the Firebase console, and replace the one in your Xcode project with it. In that case the SDK will pick up the URL from the updated file.

  • Related