Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/117.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 验证后,未从所有视图中删除视图_Ios_Swift_Firebase_Firebase Authentication - Fatal编程技术网

Ios 验证后,未从所有视图中删除视图

Ios 验证后,未从所有视图中删除视图,ios,swift,firebase,firebase-authentication,Ios,Swift,Firebase,Firebase Authentication,我创建了一个超级类,名为protectedview。它根据用户是否登录来隔离内容。我正在使用FireBase进行用户身份验证。我可以根据我的登录方法确认用户已通过身份验证,但当我从SuperView中删除用户时,该视图不会消失。我正在调用整个函数所在的超类的viewdidload中的checkAuthentication() let bannerView = ForceSignInBanner.instanceFromNib() as! ForceSignInBanner bannerView.

我创建了一个超级类,名为protectedview。它根据用户是否登录来隔离内容。我正在使用FireBase进行用户身份验证。我可以根据我的登录方法确认用户已通过身份验证,但当我从SuperView中删除用户时,该视图不会消失。我正在调用整个函数所在的超类的
viewdidload
中的
checkAuthentication()

let bannerView = ForceSignInBanner.instanceFromNib() as! ForceSignInBanner
bannerView.delegate = self

if (!AuthenticationService.sharedInstance.isAuthenticated()) {
    print("Sign them up")
    self.view.addSubview(bannerView)

} else if(AuthenticationService.sharedInstance.isAuthenticated()){
    bannerView.removeFromSuperview()
}

您的代码是必需的,因此它只在调用viewDidLoad的那一刻起作用,而不是在视图控制器的生命周期的后期起作用。为了正确处理此问题,您需要使用
addStateDidChangeListener
。例如:

self.bannerView = ForceSignInBanner.instanceFromNib() as! ForceSignInBanner
bannerView.delegate = self

handle = Auth.auth().addStateDidChangeListener { [unowned self] (_, user) in
    if user != nil {
        self.bannerView.removeFromSuperview()
    }
    else {
        self.view.addSubview(self.bannerView)
    }
}

这样,每当用户的授权状态发生变化时,就会调用关闭。

您从何处获得了处理?您只是将其声明为var还是let?也感谢您的帮助。
handle
是在视图控制器上声明的变量(以及
bannerView
)。当你不想再听的时候,它用来“关闭”听者。了解更多信息,请访问