簡體   English   中英

setValue方法未更新到Firebase數據庫

[英]setValue method not updating to Firebase database

我正在嘗試測試將數據保存到Firebase數據庫中,但是遇到了一些問題。 這是用戶按下“提交”按鈕時需要的代碼:

    var ref = FIRDatabase.database().reference()
var user = FIRAuth.auth()?.currentUser

@IBOutlet weak var titleEntry: UITextField!

@IBOutlet weak var townAndZip: UITextField!

@IBOutlet weak var pickPrice: UISegmentedControl!

@IBOutlet weak var pickDuration: UISegmentedControl!

@IBAction func tapBackground(sender: AnyObject) {
    view.endEditing(true)
}

@IBAction func postTask(sender: AnyObject) {

    if ((titleEntry.text?.isEmpty) != nil && (townAndZip.text?.isEmpty) != nil) {

        var price:String = pickPrice.titleForSegmentAtIndex(pickPrice.selectedSegmentIndex)!
        var duration:String = pickDuration.titleForSegmentAtIndex(pickDuration.selectedSegmentIndex)!

        self.ref.setValue(["title": titleEntry.text!])
        self.ref.child("tasks").child(user!.uid).setValue(["price": price])
        self.ref.child("tasks").child(user!.uid).setValue(["duration": duration])
        self.ref.child("tasks").child(user!.uid).setValue(["town_zip": townAndZip.text!])

        self.performSegueWithIdentifier("postAdd", sender: self)
        print("Posted!")

    } else {
        let alert = UIAlertController(title: "Error", message: "Please make sure you filled in everything.", preferredStyle: UIAlertControllerStyle.Alert)
        alert.addAction(UIAlertAction(title: "Understood!", style: UIAlertActionStyle.Default, handler: nil))
        self.presentViewController(alert, animated: true, completion: nil)
    }

無論我輸入什么內容,該應用程序都會執行segue,並且不會在我的Firebase數據庫中更新。 另外,如果我僅輸入其中一個字段的數據,它仍然會執行segue,並且不會顯示警報。 我以為這是Firebase本身的問題,但這很可能是我找不到的錯誤。 任何幫助將不勝感激。

您是否嘗試檢查“規則”標簽? (就在“數據”標簽之后)。

在此處輸入圖片說明

如果您尚未授權,firebase將不允許您寫入數據。 要忽略的是,您可以將規則更改為此

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

但是:從現在開始,即使沒有授權,您的應用程序的任何用戶都可以修改您的數據庫 ,我建議您將其用作臨時hack。

暫無
暫無

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

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