大佬教程收集整理的这篇文章主要介绍了ios – Firebase查询错误处理,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
// loads the current user's information static func loadUserDataWithCompletion(completion: (UserInfo) -> Void) { let ref = FIRDatabase.database().reference() print("loading current user data...") let uid = (FIRAuth.auth()?.currentUser?.uid)! ref.child("users").queryorderedByKey().queryEqualToValue(uid).observeEventType(.ChildAdded,withBlock: { (snapshot) in print("found user data!") if let Dictionary = snapshot.value as? [String:AnyObject] { let info = userFromDict(Dictionary) // execute code slated for completion completion(info) } }) }
有没有办法可以使用observeEventType检测错误?也许那时我至少会获得有关问题发生原因的更多信息.
>您尚未定义数据库观察查询的正确路径
>您正在以错误或错误的方式进行解析
>您无权在该特定时间访问该特定节点(安全规则)
对于前两个你必须自己照顾它,但对于第三个条件,你可以使用withCancel块: –
FIRDatabase.database().reference().child("users").queryorderedByKey().queryEqual(toValue: "uid").observe(.childAdded,with: { (snapshot) in //your code },withCancel: {(err) in print(err) //The cancelBlock will be called if you will no longer receive new events due to no longer having permission. })
>对于错误处理,如果用户在写入时丢失网络连接,则无论网络延迟或连接如何,您的应用程序都会保持响应.请参阅Firebase Docs的脱机写数据部分
以上是大佬教程为你收集整理的ios – Firebase查询错误处理全部内容,希望文章能够帮你解决ios – Firebase查询错误处理所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。