gpt4 book ai didi

ios - 火力地堡, swift : Not able to retrieve Data

转载 作者:搜寻专家 更新时间:2023-10-31 08:25:28 24 4
gpt4 key购买 nike

我正在尝试执行一项简单的任务,即从 Firebase 获取值。我在下面的图片中添加了相关屏幕。至少有一个打印命令应该向控制台打印一条消息,但它不起作用。我已经尝试修复它 1.5 天了,但我仍然不知道为什么它不起作用。

代码:

import UIKit
import Firebase

class MainVC: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()

let ref = FIRDatabase.database().reference()

ref.child("zonneschijn").observeSingleEventOfType(.Value, withBlock: { snapshot in
if snapshot.value is NSNull {
print("Does not exist currently")
} else {
print("Exists currently")
}

})
}
}

我也尝试过使用 viewDidAppear,但也没有成功。

Image with the relevant screens

最佳答案

如果您不对您的用户进行身份验证。

在 Firebase 控制台的 Realtime Database 中转到 Rules 选项卡。

firebase 的默认安全规则是这样的:-

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

}
}

这意味着只有经过身份验证的用户(那些已经使用 gmail、Facebook、gitter、电子邮件等登录的用户)才能读取或写入数据...显然,您没有对您的用户进行身份验证,这就是为什么您无法使用这些默认安全规则检索任何数据的原因。

这是一个很好的做法,只允许经过身份验证的用户访问数据库,因为它更安全。如果您无论如何都想读取数据,请将您的安全规则修改为:-

警告:- 不推荐如果您制作的应用有一些私有(private)数据库。

   // These rules give anyone, even people who are not users of your app,
// read and write access to your database

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

更好的选择:-

请阅读:Security Rule's

关于ios - 火力地堡, swift : Not able to retrieve Data,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39410732/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com