我正在尝试制作一个使用firebase进行身份验证和数据库的应用。这是我的第一个使用firebase的应用程序,我无法将文件保存到firebase数据库。我在运行应用程序时没有在控制台中收到任何错误,但它没有保存任何内容到firebase。我阅读了firebase文档并按照说明操作,但我无法使其工作。帮助将不胜感激。这是我的代码 导入UIKit 导入Firebase 导入FirebaseDatabase
class AddVC: UIViewController {
var refAttractions: DatabaseReference! //defining firebase database reference
@IBOutlet weak var addedlbl: UILabel!
@IBOutlet weak var descriptioninfo: UITextField!
@IBOutlet weak var categoryinfo: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// accessing nodes of refAttractiions
refAttractions = Database.database().reference().child("Attractions")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func submitbtn(_ sender: Any) {
addAttractions()
}
func addAttractions(){
let key = refAttractions.childByAutoId().key //creating id for the attraction.
let attraction = ["id": key,
"category": categoryinfo.text! as String,
"description": descriptioninfo.text! as String ]
refAttractions.child(key).setValue(attraction)
}
@IBAction func backbtn(_ sender: Any) {
dismiss(animated: true, completion: nil)
}
}
此外,我已将firebase数据库中的规则更改为true以进行读取和写入。任何帮助将不胜感激。