“runTransactionBlock: usage detected while persistence is enabled. Please be aware that transactions will not be persisted across app restarts”
可能有什么不对?
Firebase runTransaction Code
postRef.runTransactionBlock({ (currentData: FIRMutableData) -> FIRTransactionResult in if var post = currentData.value as? [String : AnyObject],let uID = FIRAuth.auth()?.currentUser?.uID { var stars : Dictionary<String,Bool> stars = post["likeMap"] as? [String : Bool] ?? [:] var likeCount = post["likeCount"] as? Int ?? 0 if let _ = stars[uID] { // Unstar the post and remove self from stars likeCount -= 1 self._liked = false stars.removeValue(forKey: uID) } else { // Star the post and add self to stars likeCount += 1 self._liked = true stars[uID] = true } post["likeCount"] = likeCount as AnyObject? post["likeMap"] = stars as AnyObject? self._likeCount = likeCount // Set value and report transaction success currentData.value = post return FIRTransactionResult.success(withValue: currentData) } return FIRTransactionResult.success(withValue: currentData) }) { (error,committed,snapshot) in if let error = error { print(error.localizedDescription) } }解决方法 不确定您使用的是哪个版本的Firebase SDK,但我将为您提供一个成功使用runTransactionBlock的基本示例:
数据库
码
let ref = FIRDatabase.database().reference()let refReservations = ref.child("reservations")refReservations.runTransactionBlock { (currentData: FIRMutableData) -> FIRTransactionResult in if var data = currentData.value as? [String: Any] { var count = data["count"] as? Int ?? 0 count += 1 data["count"] = count currentData.value = data } return FIRTransactionResult.success(withValue: currentData)}
注意
我使用过Firebase SDK版本:3.0.1,您可以使用以下方法从代码中获取此信息:FIRDatabase.sdkVersion()
@H_404_0@ 总结以上是内存溢出为你收集整理的ios – Firebase runTransactionBlock无法在swift 3中运行全部内容,希望文章能够帮你解决ios – Firebase runTransactionBlock无法在swift 3中运行所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)