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)
}
}