How to use Firebase Database to update in-app URLs in real time.

Hello,

I'm hoping someone can provide me with some suggestions as to how I can use a Firebase Database to store and update URLs to websites that are accessible within my app so that I do not have to upload a new version to the App Store every time a URL changes.

Basically there are buttons throughout my app that open webviews using Safari Services. My problem is that many of the websites change or update their URLs, which then leads to errors when my users select the buttons to visit those websites. What I'd like to do is, when I find URLs that no longer work, to be able to update the various URLs in a Firebase Database without having to update the URLs within my app's code, requiring a full update through the App Store.

Also, I currently have a Firebase Database that I've set up to store user information when they sign up, so I'm at least a little bit familiar with that aspect of Firebase.

As always, thank you for your help!

Replies

Update: So I have my Firebase real-time database populated with some data, and I have already integrated Firebase within my app, and the database's structure looks like this:

myDatabase
.
.
. . . Child/node
.
.
.
. . . Child with value of "url"

How do I reference and read the value (the URL) from the database so that the following code uses that URL to open the SFSafariViewController?

Here is the code I use to open the SFSafariViewController using a button tap:

Code Block @IBAction func openSFWebView(_ sender: Any) {
        guard let url = URL(string: "https://www.google.com")
            else {return}
        let safariViewController = SFSafariViewController (url: url)
        self.present(safariViewController, animated: true, completion: nil)
    }

From what I could find online, it seems like I should use observeSingleEventType, but I do not want to have to/don't believe I need to authenticate the user or use the user's ID to access the URL.

Below is from the Firebase documentation:
let newID = Auth.auth().currentUser?.uid (I don't believe I need this.)
ref.child("childName").child(userID!).observeSingleEvent(of: .value, with: { (snapshot) in
  // Get user value
  let value = snapshot.value as? NSDictionary
  let username = value?["username"] as? String ?? ""
  let user = User(username: username)

  // ...
  }) { (error) in
    print(error.localizedDescription)
}

Again, I hope someone can help.

Thank You!