0

I am a newbie swift developer and I am creating an iOS app using Firebase.

In my app I want two users to establish a private session where they can share some content like images and messages. I created a log-in button where the users can log-in in Firebase anonymously; what I don't know is how to create a sort of dynamic url for my FB app, so two users can establish a session share the content they want, without affecting other two users establishing a new session to share the content it pleases them the most.

All the examples I studied had a static url for the FB db so all the users running the same app are saving the data at the same url; a possible solution to solve my problem is to create a url where I concat the two anonymous usernames created during the login phase, but I don't know if this is the best solution.

Please can someone point me in the right direction on how to so solve my problem?. Thanks a lot!

Code added

class ViewController: UIViewController {

        var currentUID: String?
        let firebaseDBRef = Firebase(url:"https://trialapp.firebaseio.com")

        @IBOutlet weak var loginView: UIView!

        override func viewDidLoad() {
            super.viewDidLoad()
        }

        @IBAction func loginAnonimously(sender: UIButton) {
            firebaseDBRef.authAnonymouslyWithCompletionBlock { error, authData in
                if error != nil {
                    // There was an error logging in anonymously
                } else {
                    // We are now logged in
                    self.loginView.hidden = !self.loginView.hidden
                    self.createFirebaseRootWithUsername(authData.uid)
                    self.currentUID = authData.uid
                }
            }
        }

        func createFirebaseRootWithUsername(usernameString: String) {
             let firebaseKey = firebaseDBRef.childByAutoId()
             firebaseKey.childByAppendingPath("users").childByAppendingPath("userName").setValue(usernameString)
        }
    }
  • This has been asked quite a few times already, including recently. Have a look at http://stackoverflow.com/questions/34033725/whats-a-preferred-way-of-creating-a-chatroom-on-firebase-swift-for-two-matched, http://stackoverflow.com/questions/33540479/best-way-to-manage-chat-channels-in-firebase/33547123#33547123, http://stackoverflow.com/questions/34464702/retreiving-data-from-firebase-for-chat-system/34466816#34466816 and http://stackoverflow.com/questions/33540479/best-way-to-manage-chat-channels-in-firebase/33547123#33547123 (with a code sample) – Frank van Puffelen Feb 05 '16 at 02:03
  • Frank thank you so much for your help. I am following your guidelines about concatenating the 2 usernames and create a random FB url with them where to save the content of a private chat. My problem is how to create a room concatenating two usernames that are not on the same devices; I mean user 1 logs-in anonymously on the app running on its devices and so does the user 2, but I don't understand how to keep them in touch pointing to a unique url generated by the concatenation of both their anonymous urls...Do you have suggestions? Thank you so much for your help again – user4950087 Feb 05 '16 at 20:05
  • Can you show the code of what you're doing? It'll be much easier to help that way. [Edit your question](http://stackoverflow.com/posts/35214376/edit) and put it in there. – Frank van Puffelen Feb 05 '16 at 20:13
  • Frank I have updated the post with the code. Right now it manages only the login anonymous login. Let me know if you can't see it correctly and I will try to post it again. Thanks for your help – user4950087 Feb 05 '16 at 20:43

0 Answers0