Advertisement
Guest User

Untitled

a guest
Apr 5th, 2017
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. "users" : {
  2. "userId1" : {
  3. "name" : "Alex",
  4. "email" : "alex@gmail.com",
  5. "phoneNumber" : "123456789"
  6. },
  7. "userId2" : {
  8. "name" : "Ben",
  9. "email" : "ben@gmail.com",
  10. "phoneNumber" : "223456789"
  11.  
  12. },
  13. "userId3" : {
  14. "name" : "Charles",
  15. "email" : "charles@gmail.com",
  16. "phoneNumber" : "323456789"
  17.  
  18. }
  19. }
  20.  
  21. self.ref = FIRDatabase.database().reference()
  22. ref.child("users").child("userID").observeSingleEventOfType(.Value, withBlock: { (snapshot) in
  23.  
  24. if snapshot.hasChild("phoneNumber"){
  25.  
  26. print("Phone number exist")
  27.  
  28. }else{
  29.  
  30. print("Phone number doesn't exist")
  31. }
  32.  
  33.  
  34. })
  35.  
  36. FIRDatabase.database().reference().child("users").child("userID").child("phoneNumber").observeSingleEvent(of: .value, with: {(snap) in
  37.  
  38. if snap.exists(){
  39.  
  40. //Your user already has a Phone number
  41.  
  42. }else{
  43. //Phone number not available
  44.  
  45. }
  46. })
  47.  
  48. var userRef : FIRDatabaseQuery = FIRDatabase.database().reference().child("users")
  49. userRef = userRef.queryOrdered(byChild: "phoneNumber").queryEqual(toValue: <NUMBER>)
  50. userRef.observe(FIRDataEventType.value, with: { (snapshot) in
  51. if snapshot.value != nil {
  52. //value exists
  53. }
  54. }, withCancel: { (error) in
  55. //search error
  56. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement