Tag: firebase database

负面的时间戳得到错误的post列表

我被困在一个棘手的小问题上,所以请帮助 (此代码有效)我使用下面的代码来获取最新的post,使用negativeTimestamp:哪个是使用FIRServer,然后查询和负面。 FIRDatabase.database().reference().child("post").child(animal).queryOrdered(byChild: "negativeStamp").queryEnding(atValue: startValue – 1, childKey: "negativeStamp").observe(.childAdded, with: {(snapshot) in 我也使用下面的查询来获得所有的post, 这完美的作品 。 我最终得到最新的项目。 ref.child("post").child(animal).queryOrdered(byChild: "negativeStamp").queryLimited(toFirst: 5).observeSingleEvent(of: .value, with: {(snapshot) in 当我尝试获取tableView的接下来的5个元素时,问题就出现了。 我无法顺序查询5个元素? 我正在使用这个代码。 Self.timestampArray.last将是tableView中显示的最后一个post。 let endingValue: Int = self.timestampArray.last! let timeIntervalToday: TimeInterval = (NSDate().timeIntervalSince1970) * -1 FIRDatabase.database().reference().child("post").child(animal).queryOrdered(byChild: "negativeStamp").queryEnding(atValue: (endingValue + 1)).observe(.value, with: {(snapshot) in 我也使用这个tableView函数来知道用户何时到达底部 。 希望这不是太多的阅读。 func tableView(_ tableView: UITableView, willDisplay […]

Firebase imageview数组

在我的应用程序中,我正在使用自定义图像数组视图。 用户上传的每个post的许多图像应该是以旋转木马般的方式显示的多个图像。 在firebase,我有价值从图像到imageFive { "image" : "W585B.jpg", "imageFive" : "", "imageFour" : "", "imageThree" : "", "imageTwo" : "", } 正如你在这个例子中看到的,只有一个值有一个string。 用户可以发布一到五个图像。 我想追加用户上传的许多图像并将其显示在传送带上。 这是我现在所拥有的。 var imageArray = [UIImage]() override func viewDidLoad() { super.viewDidLoad() if let stringImage = self.imageNames { let imageRef = storage.reference(forURL: "gs://gsignme-14416.appspot.com/images/\(stringImage)") imageRef.data(withMaxSize: 25 * 1024 * 1024, completion: { (data, error) -> […]

Swift FIRMessaging推送通知令牌重置

我目前正在使用推送通知工作,因此我正在尝试生成推送令牌。 我的问题是什么时候这些到期? 我将每个用户推送令牌存储在我的Firebase数据库中,但是我知道这些令牌过期/重新生成自己。 所以我的问题是,持续推送令牌是最新的最好方法是什么? 每当用户导航到他们的个人资料时,我是否会简单地执行此操作? let token = FIRInstanceID.instanceID().token() ref.child("Users").child(id).child(pushToken).updateChildValues(["tokenid":token]) 你看,现在我要求用户在注册后立即允许推送通知,但不知怎的,它似乎仍然会生成一个令牌ID,即使我拒绝请求。 所以我的问题是,我怎么能保持这个令牌ID更新? 我需要在AppDelegate中做这个吗? 谢谢。 帮助非常感谢!

有效查询Firebase

我想从每个用户名称值search我的用户群。 从我在网上看到的人们经常返回所有的用户,然后在表格视图中筛选,但这似乎并不实际,也不可行。 我的想法是查询数据并返回指数级数值的数组,但是我在使用提供的查询方法时遇到了问题。 如何查询我的数据库的特定方面? 我如何构build我的代码,使其可行 ; 不加载每个用户,一次最多10个。 任何build议,资源和链接,不胜感激。 编辑: 我做了一些研究,看起来Firebase带有一些内置的查询方法…到目前为止,这是我试图用下面的代码来testing它打印出用户从我开始,但我不能它打印控制台中的任何用户 ref.queryOrderedByKey().queryStarting(atValue: "I").queryEnding(atValue: "I\u{f8ff}") .observe(.childAdded, with: { snapshot in print(snapshot.key) })

从Firebase中检索图片

Firebase数据库结构的扩展 将图片,姓名和电话上传到Firebase数据库和Firebase存储后。 我无法从Firebase检索图片到表格视图。 这是表视图类: @IBOutlet var tableViewHongKong: UITableView! var restaurantList = [RestaurantModel]() override func viewDidLoad() { super.viewDidLoad() ref = FIRDatabase.database().reference().child("restaurants") ref?.observe(FIRDataEventType.value, with: {(snapshot) in if snapshot.childrenCount>0 { self.restaurantList.removeAll() for restaurants in snapshot.children.allObjects as![FIRDataSnapshot] { let restaurantObject = restaurants.value as? [String: AnyObject] let restaurantName = restaurantObject?["name"] let restaurantPhone = restaurantObject?["phone"] let restaurant = RestaurantModel(name: name as! […]

Firebase数据库结构 – 需要build议

我知道这个问题可能被看作是一个基于意见的问题,但我认为值得讨论如何正确构build数据库。 我在Swift的iOS应用上工作,并决定使用Firebase作为我的后端服务 我们从应用程序描述开始 该应用旨在提供跟踪和社交function来预订阅读体验,以及创build图书数据库。 用户添加书籍,填写基本信息,如标题,作者,语言,页数等。接下来,本书在应用程序列表中可见,用户可以轻松访问书籍信息并将其最近保存在哪个页面结束阅读。 一本书被标记为阅读后,用户获得经验点和徽章。 最终,用户将能够浏览朋友的成就,创build排行榜等。 这是我的数据库结构的想法: Users: user_id:121jhg12h12 email: "john@doe.com" name: "John Doe" profile_pic_path: "https://…". language: "en" exp_points: 1284 friends: [user_id] books: [[book_id, status, current_page, start_date, finish_date]] badges: [[badge_id, get_date]] Books: book_id: 3213jhg21 title: "For whom the bell tolls" author: "Ernest Hemingway" language: "en" pages_count: 690 ISBN: "21hjg1" year: 2007 Badges: badge_id:213hg12 name: […]

当应用程序处于后台iOS时的Firebase数据库事务

我正在使用交互式推送通知,当我回复PN时,应该更新firbase数据库。 它不能很好的工作,因为有些时候,如果应用程序在后台数据没有实时同步。 但是当你打开应用程序,它会推动数据 如果应用程序处于死亡状态,则答复甚至不会发送到Firebase数据库 Ref.child(uId).runTransactionBlock({ (currentData: FIRMutableData) -> FIRTransactionResult in var value = currentData.value as? [String : AnyObject] if value == nil { return FIRTransactionResult.success(withValue: currentData) } let totR = value!["totalReply"] as? Int ?? 0 print(totR) value?["totalReply"] = totR + 1 currentData.value = value }

在Firebase SDK v3中使用数据库秘密进行身份validation?

首先,我喜欢新的Firebase。 不过,我无法让我的Swift项目连接到Firebase,因为我正在使用数据库秘密来validation设备。 在Firebase SDK第3版之前,我可以使用Firebase秘密(现在是数据库机密)进行身份validation以访问我的数据库。 我能够使用下面的代码块来做到这一点: ref.authWithCustomToken("authKeyHere", withCompletionBlock: { error, authData in if error != nil { print("Login failed! \(error)") } else { print("Login to firebase succeeded! \(authData)") } }) 这对我很好,因为我只是authentication我的应用程序的用户,并没有公开整个数据库,可以这么说。 我试图用新的Firebase SDK(v3)实现同样的function。 我已经添加了必要的豆荚到我的项目,据我所见,我需要使用下面的代码来实现同样的事情: FIRApp.configure() FIRAuth.auth()?.signInWithCustomToken("authKeyHere") { (user, error) in //This signs in using the authentication secret so we can now access the database. if error […]

从匿名数据库中删除匿名用户

我正在使用Firebase数据库,并且与下一个情况有点混淆。 让我们想象我有待办事项的应用程序。 我使用标准的Firebase身份Auth系统在用户设备之间同步items 。 但在其他情况下,用户可以匿名工作而不需要同步。 步骤1: 用户启动应用程序第一次,并在AppDelegate我创build匿名用户: FIRAuth.auth()?.addStateDidChangeListener { auth, user in if let _user = user { if _user.isAnonymous { print("User logged in as anonymous. Saving uid to user defaults storage.") UserDefaults.standard.setValue(_user.uid, forKey: "uid") } else { print("User logged in with email: \(_user.email)") } } else { FIRAuth.auth()?.signInAnonymously() { (user, error) in if let […]

Firebase或Swift没有检测到变音符号

我在Firebase数据库/存储中发现了一些最古怪的东西。 问题是,我不知道Firebase或Swift是否没有检测到变音器,例如(ä,ö,ü)。 我使用Firebase做了一些简单的事情,例如将图片上传到Firebase存储,然后将其下载到tableview 。 例如,我的一些.png文件在标题中有元音变音( Röda.png )。 所以现在如果我下载它们,问题就会出现。 只有当我的下载url是nil ,如果文件名包含我所说的变音符号。 所以我尝试了一些替代方法,如HTML ö – ö 。 但是这不起作用。 你们可以给我一些build议吗? 我不能用ö – o , ü – u等 这是在尝试将某些值设置为Firebase时, url nil时的代码: FIRStorage.storage().reference() .child("\(productImageref!).png") .downloadURLWithCompletion({(url, error)in FIRDatabase.database().reference() .child("Snuses").child(productImageref!).child("productUrl") .setValue(url!.absoluteString) let resource = Resource(downloadURL: url!, cacheKey: productImageref)