【发布时间】:2017-03-10 12:31:29
【问题描述】:
我正在尝试使用此代码从 Firebase 数据库中获取用户,但出现此错误
取消错误 Error Domain=com.firebase Code=1 "Permission Denied" UserInfo={NSLocalizedDescription=Permission Denied}
我的规则应该如何设置?
代码如下:
FIRDatabase.database().reference().child("users").observe(.childAdded, with: { (snapshot) in
print("snapshot \(snapshot)")
//all users right here n shyt
if let dictionary = snapshot.value as? [String: AnyObject] {
let user = User()
//class properties have to match up with firebase dictionary names
user.setValuesForKeys(dictionary)
self.users.append(user)
DispatchQueue.main.async {
self.messageTable.reloadData()
}
}
print(snapshot)
}, withCancel: { (error) in
print("cancel error \(error)")
})
这是我在 Firebase 中的规则:
{
"rules": {
"users": {
"$uid": {
".read": "$uid === auth.uid",
".write": "$uid === auth.uid"
}
}
}
}
【问题讨论】:
-
您肯定希望将代码放入
withCancel以检测读取是否被取消。见stackoverflow.com/documentation/firebase/5548/… -
同时给出最小的 JSON 树结构。
-
我按照弗兰克说的去做,然后返回错误,说“取消错误 Error Domain=com.firebase Code=1 "Permission Denied" UserInfo={NSLocalizedDescription=Permission Denied}"
标签: ios firebase firebase-realtime-database swift3