Firebase Swift注销内存分配

时间:2018-10-03 07:15:31

标签: ios swift firebase firebase-authentication

我正在尝试从Firebase的iOS设备注销用户。如下代码所示,当调用firebaseCheckOut时,用户注销了iOS设备,他们会重新选择登录页面。一切正常,但是,当用户注销时,此函数所在的viewcontroller( NetworkController )不会取消分配。我该如何取消分配 NetworkController ,以便它不会在用户每次退出Firebase时都建立起来?

class NetworkController: NSObject {

    func firebaseCheckOut(){ 
            var handle : NSObjectProtocol = 0 as NSObjectProtocol
            handle =  Auth.auth().addStateDidChangeListener { (auth, user) in
                if user != nil {

                    let userID = Auth.auth().currentUser!.uid

                    guard userID != nil else { return}
                    do {

                        self.firebaseSetValue("userz1234/\(userID)", false as AnyObject)

                        Auth.auth().removeStateDidChangeListener(handle)

                        try Auth.auth().signOut()
                    }
                    catch let signOutError as NSError {
                    }
                }
            }
        }
    }

在以下视图控制器中,通过调用firebaseCheckOut退出并选择登录页面来调用注销按钮:

class LogOutViewController: UIViewController {

    weak var networkController: NetworkController!

    public func displayLogOutAlert(title:String, message:String, button:String) {

        let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)

        alertController.addAction(UIAlertAction(title: button, style: .default, handler: {[unowned self] (alertController) in

            self.networkController?.firebaseCheckOut()

            self.performSegue(withIdentifier: "toSignIn", sender: Any?.self)

        }))
    deinit {
        debugPrint("Logout Deinit...")
    }
}

0 个答案:

没有答案