簡體   English   中英

無法讀取Firebase數據

[英]Can't read firebase Data

我有一個項目,我想在不驗證身份的情況下讀取firebase數據,我已經將數據庫規則更改為以下內容:

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

我也嘗試過

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

火基結構圖像

我的代碼是:

 db = Database.database().reference()
    db.child("users").observe(.value, with: { snapshot in

        print(snapshot)

    })

}

它沒有給我任何錯誤,只是沒有提取數據

如果您確保設置為true。 檢查此代碼。

let ref = Database.database().reference(withPath: "users")
print(ref)
ref.observeSingleEvent(of: .value, with: { snapshot in
if !snapshot.exists() { return }
print(snapshot)
})

我找到了解決方案。 正如@RosárioPereira Fernandes所說,錯誤是因為我的Firebase數據庫規則中帶有引號。

像這樣:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM