2017-07-03 56 views
2

如何在我的swift代码中检查“permission_denied”?!以便我可以向用户显示正确的警报?如何检查Firebase权限是否被拒绝?

self.ref = Database.database().reference(withPath: "PlayerBoxes") 
    // 
    handle = ref.child(pID).observe(.value, with: { snapshot in 
     // Do Something 
    }) { (error) in 
     print(error.localizedDescription) 
    } 



    // Update info into Firebase, do not overwrite entire node 
    ref.child(self.pID).updateChildValues(sqr.toDictionary()) <-- Permission Denied 
+0

请接受我的回答作为答案,因为它解决了您的问题,并且您的问题被关闭。快乐编码:) – eshirima

回答

2

您需要改为使用updateChildValues(withCompletionBlock:)

这将返回数据库引用以及任何引发的错误。

ref.child(self.pID).updateChildValues(sqr.toDictionary()) { (error, reference) in 
    if error != nil 
    { 
     // handle the error 
     print(error!.localizedDescription) 
    } 

    // you're fine, no error raised 
}