示例代码,创建一个界面,界面含有一个监听,成功之后传给调用Manager的类
import UIKit
public class Manager: NSObject {
public static let getInstance = Manager()
func start(self:UIViewController,callBack: ((_ msg:String) -> Void)? = nil) {
let viewController = UIStoryboard.init(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "ViewController") as! ViewController
viewController.Start(callBack: callBack)
// viewController.modalPresentationStyle = .fullScreen
self.present(viewController, animated: true, completion:nil)
}
}
ViewController监听调用
public func start(callBack: ((_ msg:String) -> Void)? = nil) {
handle = Auth.auth().addStateDidChangeListener { auth, user in
if user == nil{
// go to main screen if there is a user logged in
print("登出状态")
self.loginContext.text = "User is signed out !"
}else{
//go to login screen
self.currentUser = user
print("登录状态")
self.loginContext.text = "UserId:\(user?.uid ?? "")\nProviderId:\(user?.providerID ?? "")\nDisplayName:\(user?.displayName ?? "")\nPhoneNum:\(user?.phoneNumber ?? "")\nEmail:\(user?.email ?? "")\nIsEmailVerified:\(user!.isEmailVerified)\nPhotoUrl:\(user?.photoURL?.absoluteString ?? "")"
}
guard let _callBack = callBack else { return }
_callBack(user?.providerID ?? "")
}
}
调用
Manager.getInstance.startLogin(self: self) { msg in
print("数据传递成功------>"+msg)
}
网友评论