Observer的完成处理程序未被调用,如何检入代码 [英] Observer's completion handler not called, how to check in code

查看:188
本文介绍了Observer的完成处理程序未被调用,如何检入代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Firebase和Swift,与Instagram进行自定义身份验证。

我现在有这个问题,通过仪表板删除用户,但用户仍然登录?



当我启动我有这个监听器:

$ p $ Auth.auth()。addStateDidChangeListener {



其中我设定观察者:

  ref.child(users / \(user.uid))。在
中打印(快照)观察(.value):{(快照)
.........
},withCancel:{
print(error)
})

with withCancel 处理程序不会执行,因为用户的令牌不再存在。 (非常奇怪的IMO甚至 withCancel 不会执行)。



我必须在代码中捕捉到这种情况,才能强制注销,就像这个帖子所说:

$


检查您是否可以阅读您的用户区域,如果没有任何内容,强制退出。 >解决方案

我最终向Firebase报告了一个错误报告。
我会发布回复,因为它可能会帮助某人在未来。


来自Firebase的人回应了这个消息,


设计意图。即使您已经从应用程序的
中删除了用户,用户的
会话也会无限期地持续下去。为了帮助你解决这个问题,你可以在
之后检查一下StackOverflow的帖子,可能会给你更多关于
的信息。


更多关于这个的信息,我坚持使用cancel块,为什么它没有执行:

我不不理解为什么 withCancel 完成处理程序没有被调用。
from:

$ b

  ref.child(users / \(user.uid) ).observe(.value,其中:{(snapshot)in 
print(snapshot)
..........
},withCancel:{
print(error)
))

,应用程序不会停止。所以,即使是 withCancel 也不会被调用。

答案:


withCancel 完成处理程序查询,让我只需
在这里给你一些信息。如果
客户端未经身份验证,并且不再有权限接收
事件,则会调用取消块。此外,还值得一提的是,在离线模式下不会调用取消块
,因为Firebase旨在在此条件下正常工作
。您可以查看我们的文件以了解更多
的详细信息。



I use Firebase and Swift, for a custom auth with Instagram.

I have this problem now, Remove a user through dashboard, but the user is still logged in?

When I start the app, I have this listener:

Auth.auth().addStateDidChangeListener {

in which I am setting an observer:

ref.child("users/\(user.uid)").observe(.value, with: { (snapshot) in
        print(snapshot)
        ..........
    }, withCancel: { error in
        print(error)
    })

with and withCancel handlers are not executed, because user's token does not exist anymore. ( very weird IMO that even withCancel does not execute).

I have to catch this situation in code, to force a logout, like the post stated:

check whether you can read to your users area, and if there's nothing there, force a log out.

解决方案

I ended up reporting a bug report to Firebase. I will post the response, since it may help someone in the future.

The guys from Firebase responded this,

The behavior you have described is intended by design. A user's session persists indefinitely even if you have deleted the user from the application. To help you with this scenario, you may check on the following StackOverflow posts that might give you more information on how to handle this one.

More on this, I have insisted with the cancel block, why it did not execute:

I don’t understrand why withCancel completion handler is not called. from this:

 ref.child("users/\(user.uid)").observe(.value, with: { (snapshot) in 
     print(snapshot) 
     .......... 
     }, withCancel: { error in 
        print(error)  
     }) 

When I put breakpoints on both prints, app does not stop. So, even withCancel is not called.

The answer:

Going to your withCancel completion handler inquiry, let me just give you a bit of information here. Cancel blocks are called if the client is unauthenticated and no longer has permission to receive events. Additionally, it is also worth mentioning that cancel blocks are not called during offline mode as Firebase is designed to work well in this condition. You may check our document for further details.

这篇关于Observer的完成处理程序未被调用,如何检入代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆