I have tried many solutions to make this work, but it doesn't seem to work with me. These are the solutions I have tried:
Firebase Retrieving Data in Swift
https://firebase.google.com/docs/database/ios/read-and-write
https://www.raywenderlich.com/187417/firebase-tutorial-getting-started-3
I am trying to retrieve the deviceToken of the currently logged in user, for example if John logs in, it would assign or retrieve his deviceToken and assign it to a variable.
The closest I have got was with this code, but I get every profile with every data stored in that profile instead of the currently logged in one.
let userID = Auth.auth().currentUser?.uid
let ref = Database.database().reference(withPath: "users/profile/\(userID)")
ref.observeSingleEvent(of: .value, with: { snapshot in
if !snapshot.exists() {
return
}
let token = snapshot.childSnapshot(forPath: "deviceToken").value
print(token!)
})