11. Swift 玩 FireBase
可能有很多朋友會問,同樣都是 Google 自己的分析產品,那老牌的 Google Analytics 不是也可以做 APP 的分析
嗎?關於產品的定位和未來發展, Google 自己在官方部落格說的很清楚了:「Firebase 分析功能現在是
Google 官方推薦針對行動分析工具的解決方案!」(Firebase Analytics is now Google’s recommended
solution for mobile app analytics.)也建議大家如果同時有網站就使用 GA 做網站分析,Firebase Analytics 做
APP 分析。
雖然由於產品仍然相當新,再加上免費無限的框架下,有很多功能還不盡完善,像是在儀表板缺乏時間的屬性來
做進一步的篩選與分析,也沒辦法輸出成 CSV 自己做分析,需要透過 BigQuery,還有 iOS 要等 24 小時才會有
數據等等,但是相信對於資源缺乏的新創公司在考慮免費分析工具的選擇上,又兼具後端開發的功能,Firebase
仍不失為是有力的行動數據分析解決方案。
32. import UIKit
import Firebase
classViewController: UIViewController {
@IBOutlet weak var textField: UITextField!
@IBOutlet weak var labetFirebase: UILabel!
let rootRef = FIRDatabase.database().reference()
var snap: FIRDataSnapshot!
@IBAction func theButton(sender: UIButton) {
let s = textField.text
_ = rootRef.child("condition").setValue(s)
//let conditionRef = rootRef.child("condition")
//conditionRef.setValue(s)
}
Swift 玩 FireBase
寫入 FireBase
(兩種作法)
連結 FireBase
物件宣告
33. override func viewDidLoad() {
super.viewDidLoad()
let conditionRef = rootRef.child("condition")
// Do any additional setup after loading the view, typically from a nib.
conditionRef.observeEventType(.Value, withBlock: {
snap in self.labetFirebase.text = snap.value?.description
})
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
let conditionRef = rootRef.child("condition")
conditionRef.observeEventType(.Value) { snap in print("FireBase: (snap.value?.description)")
}
}
}
Swift 玩 FireBase
設定讀取欄位
顯示資料
顯示資料