我是一个新手试图将我的应用程序连接到后端(Firebase数据库)。具体来说,我有四个用户输入内容的字段,我试图设置一个等于每个字段的子节点。不幸的是,虽然我没有错误,但在数据库中没有帖子。我不确定我是否遗漏了大大小小的东西,所以任何指导都会非常感激。代码如下:
class ThirdViewController: UIViewController {
var ref:FIRDatabaseReference!
@IBOutlet weak var bookTitle: UITextField!
@IBOutlet weak var bookDescription: UITextField!
@IBOutlet weak var authorBiography: UITextView!
@IBOutlet weak var bookPurchaseLink: UITextView!
@IBAction func saveButtonTapped(_ sender: Any) {
let bookTitleContent = String(describing: bookTitle.text)
let bookDescriptionContent = String(describing: bookDescription.text)
let authorBiographyContent = String(describing: authorBiography.text)
let bookPurchaseLinkContent = String(describing: bookPurchaseLink.text)
func viewDidLoad() {
super.viewDidLoad()
//post to database
ref = FIRDatabase.database().reference()
self.ref.child(uuid).child("Book Info").child("Book Title").setValue(bookTitleContent)
self.ref.child(uuid).child("Book Info").child("Book Description").setValue(bookDescriptionContent)
self.ref.child(uuid).child("Book Info").child("Author Biography").setValue(authorBiographyContent)
self.ref.child(uuid).child("Book Info").child("Book Purchase Link").setValue(bookPurchaseLinkContent)
}
}
答案 0 :(得分:0)
检查Firebase规则以进行读取和写入。!
{
"rules": {
".read": "auth != null",
".write": "auth != null"
}
}
mdatabase = FirebaseDatabase.getInstance();
mdatabaseReference = mdatabase.getReference();
mdatabaseReference.child("Child").setValue(Data);
//
希望这对你有所帮助。