firebase permission_denied 当 运行 程序

firebase permission_denied when running program

我有一个问题,我在网上搜索并找到了一个答案,但它对我不起作用。我有一个应用程序,用户可以在其中 post 图像并为他们加载所有 posted 图像的提要。一个问题是我一直在输出中收到 permission_denied 的错误。我很困惑,当我查找这个问题的答案时,我得到的只是尝试 ref.removeAllObservers,但我的代码已经有了这个。这是我的代码,请查看:

 func fetchPosts () {
    let ref = FIRDatabase.database().reference()
    ref.child("posts").queryOrderedByKey().observeSingleEvent(of: .value, with: { snapshot in
        let postSnap = snapshot.value as! [String: AnyObject]
        for (_,post) in postSnap {

            let posst = Post()
            if let author = post["author"] as? String, let pathToImage = post["pathToImage"] as? String, let postID = post["postID"] as? String {
                posst.author = author
                posst.pathToImage = pathToImage
                posst.postID = postID
                self.posts.append(posst)
            }

                self.postTableView.reloadData()

        }


    })
ref.removeAllObservers()
}

如果您有答案,请告诉我。这也是输出:

2017-05-03 08:06:31.771 Postflur[21064] [Firebase/Database][I-RDB03812] Listener at /posts failed: permission_denied

很高兴听到你已经解决了它(我在评论部分看到了它),但我还是想写这个答案,因为我过去遇到过类似的问题。 所以默认情况下 firebase 数据库仅 readable/writeable 由经过身份验证的用户使用(如果您查看 firebase 控制台中的规则,您会发现以下内容):

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

因此,要让未经身份验证的用户读取/写入数据,您应该将规则更改为以下

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

这就是我的解决方案。