Firebase Database setValue: or removeValue failed: permission_denied iOS

a 夏天 提交于 2021-02-16 16:16:11

问题


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

}

回答1:


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. :)




回答2:


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



回答3:


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




回答4:


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




回答5:


Make sure to select real time database and edit the rule then publish .



来源:https://stackoverflow.com/questions/40937868/firebase-database-setvalue-or-removevalue-failed-permission-denied-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!