Firebase, Swift: unable to get data

I am trying to perform a simple task to get a value from Firebase. I have added the image below with the corresponding screens. At least one of the print commands should print a message to the console, but it does not work. I tried to fix this for 1.5 days, and I still don't know why it is not working.

the code:

import UIKit
import Firebase

class MainVC: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let ref = FIRDatabase.database().reference()

        ref.child("zonneschijn").observeSingleEventOfType(.Value, withBlock: { snapshot in
            if snapshot.value is NSNull {
                print("Does not exist currently")
            } else {
                print("Exists currently")
            }

        })
    }
}

I also tried using viewDidAppear, also without any success.

Image with corresponding screens

+4
source share
1 answer

If you do not authenticate the user.

Click the Advanced tab Rulesin the Realtime Databasein Firebase console.

The default security rules for firebase are something like this: -

{
 "rules": {
    ".read": "auth != null",
    ".write": "auth != null"

   }
}

, ( , gmail, Facebook, gitter, email..etc) ... , , - .

, , . , : -

: , , .

   // These rules give anyone, even people who are not users of your app,
    // read and write access to your database

    {
      "rules": {
        ".read": true,
        ".write": true
      }
    }

: -

:

+5

Source: https://habr.com/ru/post/1654122/


All Articles