2017-07-03 57 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 
}