Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Database setValue: or removeValue failed: permission_denied iOS

I'm trying to write data to Firebase Database but I keep receiving the following error when my saved button is pressed.

2016-12-02 11:09:42.548 StartupNow[1482:60415] [FirebaseDatabase] setValue: or removeValue: at /test/-KY-VpLZWbp4vjF3BpMk failed: permission_denied

Things I've tried: I've made sure my .read and .write rules were set to true in my console, reconnected my savedButtonPressed button, and wrote the Firebase reference in a function and called it in my savedButtonPressed() method.

Extra Resource Here is the tutorial I'm following along. https://youtu.be/F42CzqIBxHQ?t=4m14s

var ref: FIRDatabaseReference?

override func viewDidLoad() {
    super.viewDidLoad()

    ref = FIRDatabase.database().reference()

}

@IBAction func saveButtonPressed() {
   // TODO: Post data to Firebase

    firebaseChild()
    print("********************************")
    print("********************************")

}

func firebaseChild () {
    ref?.child("Test").childByAutoId().setValue("Hello Firebase")

}
like image 486
fred Avatar asked Dec 02 '16 17:12

fred


4 Answers

I had a similar issue. It was resolved by resetting the read / write rules for the database. If you changed your rules try reseting them to the default.

Warning: These rules allow anyone to read and write to your database!

Default Rules for Real-time Database

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

Default Rules for Cloud Firestore

service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write;
    }
  }
}
like image 50
DoesData Avatar answered Nov 12 '22 21:11

DoesData


FreddieOh and I chatted over Slack, and the problem was that the database that was listed in the GoogleService-info.plist file didn't match up with the one he was editing. (It looks like maybe in this case, he had deleted and recreated the project in the Firebase console, but hadn't updated the plist file.)

If you find yourself in the same situation where you've set your read and write access to true and are still getting permission denied errors, open up your GoogleService-info.plist file and look at the entry for DATABASE_URL. Then go to the Firebase Database in your project, look at the top of the data tab, and confirm that the URL listed there is the same as the one in your plist file.

I suppose the other thing to check for would be that you updated your database rules to allow global access but forgot to click the Publish button. That... may have happened to me at one point. :)

like image 30
Todd Kerpelman Avatar answered Nov 12 '22 23:11

Todd Kerpelman


Go to your Firebase console, and perform following steps which is identify in image.

Please lookup image and follow these steps. If you are beginner and facing problem in image. I make little video about error.

Video Solution : https://youtu.be/FcQCPqckvqo

Image Solution enter image description here

like image 10
Khawar Islam Avatar answered Nov 12 '22 23:11

Khawar Islam


I have solved the same issue after trying to use every resource. The only solution is that

Go to fireBase Console -->select your project -->Go to database -->select the Rules("Show in the mid next to the Data")-->make the make both option true

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

this will be work perfectly

enter image description here

enter image description here

like image 2
Muhammad Usman Avatar answered Nov 12 '22 21:11

Muhammad Usman