我无法从新的Firebase检索数据。触摸按钮后(act())没有任何变化。我检查了所有设置并阅读了Firebase网站上的所有文档,但我无法理解为什么没有发生任何事情。
import UIKit
import Firebase
var ref = FIRDatabaseReference.init()
class MainTovarViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource {
@IBOutlet weak var collectionView: UICollectionView!
var items = [FIRDataSnapshot]()
override func viewDidAppear(animated: Bool) {
}
override func viewDidLoad() {
super.viewDidLoad()
ref = FIRDatabase.database().reference()
}
@IBAction func act(sender: AnyObject) {
ref.observeEventType(FIRDataEventType.Value) { (snapshot: FIRDataSnapshot!) in
var newItems = [FIRDataSnapshot]()
for item in snapshot.children {
newItems.append(item as! FIRDataSnapshot)
}
self.items = newItems
print("\(self.items)")
self.collectionView!.reloadData()
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
var result = 0
if items.count != 0 {
result = items.count
}
return result
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("MainTovarCollectionCell", forIndexPath: indexPath) as! MainTovarCollectionCellCollectionViewCell
cell.backgroundView = UIImageView(image: UIImage(named: "product_1"))
cell.titletovar.text = items[indexPath.row].value!.objectForKey("TovarName") as! String
return cell
}
}
而且:
2016-05-21 10:55:38.340 shoroo[95390:14237917] WARNING: Firebase
Analytics App Delegate Proxy is disabled. To log deep link campaigns manually, call the methods in FIRAnalytics+AppDelegate.h.
2016-05-21 10:55:38.510 shoroo[95390:14237917] Configuring the default app.
2016-05-21 10:55:38.522 shoroo[95390:] <FIRAnalytics/INFO> Firebase Analytics v.3200000 started
2016-05-21 10:55:38.523 shoroo[95390:] <FIRAnalytics/INFO> To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled
2016-05-21 10:55:38.529: <FIRInstanceID/WARNING> Failed to fetch APNS token Error Domain=com.firebase.iid Code=1001 "(null)"
2016-05-21 10:55:38.533: <FIRMessaging/INFO> FIRMessaging library version 1.1.0
2016-05-21 10:55:38.564 shoroo[95390:] <FIRAnalytics/INFO> Firebase Analytics enabled
Error Domain=NSCocoaErrorDomain Code=3010 "REMOTE_NOTIFICATION_SIMULATOR_NOT_SUPPORTED_NSERROR_DESCRIPTION" UserInfo={NSLocalizedDescription=REMOTE_NOTIFICATION_SIMULATOR_NOT_SUPPORTED_NSERROR_DESCRIPTION}
答案 0 :(得分:0)
检查数据库授权(规则)。尝试将规则设置为:
{
"rules": {
".read": true,
".write": true
}
}