如果我先卸载应用程序,然后重新安装应用程序,则它会直接转到应用程序的主页。它不要求用户登录。
我为当前用户编写了authStateListener
,以监视在后台删除该应用程序然后重新安装该应用程序的时间,该应用程序将显示登录页面而不是主页。当用户注销时,该应用程序将显示登录页面,否则该应用程序将转到主页。因此,当用户从应用程序注销后再卸载并重新安装该应用程序时,它可以正常工作。
但是我的问题是,如果用户没有注销,然后卸载并重新安装该应用程序,那么它将显示该应用程序的主页而不是登录页面。我该如何解决?
代码是:
class ViewController: UIViewController {
var db : Firestore!
var handle:AuthStateDidChangeListenerHandle?
@IBOutlet weak var email: UITextField!
@IBOutlet weak var pswd: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
db=Firestore.firestore()
print(currentReachabilityStatus != .notReachable)
let token = Messaging.messaging().fcmToken
let authid = Auth.auth().currentUser?.uid
print("token\(String(describing: token))")
let docRef = self.db.collection("deyaPayUsers").document(authid!)
docRef.setData(["FCMToken":token as Any],options:SetOptions.merge())
self.handle = Auth.auth().addStateDidChangeListener { auth, user in
if user != nil {
if (user?.isEmailVerified)!{
let myVC = self.storyboard?.instantiateViewController(withIdentifier: "deyaPay") as!deyaPay
self.navigationController?.pushViewController(myVC, animated:true)
}
else{
let alertVC = UIAlertController(title: "Error", message: "Sorry. Your email address has not yet been verified. Do you want us to send another verification email to \(String(describing: self.email.text!)).", preferredStyle: .alert)
let alertActionCancel = UIAlertAction(title: "Cancel", style: .default, handler: nil)
//alertVC.addAction(alertActionOkay)
alertVC.addAction(alertActionCancel)
self.present(alertVC, animated: true, completion: nil)
}
}
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func viewDidAppear(_ animated: Bool) {
if currentReachabilityStatus != .notReachable
{
print("Connected")
}
else
{
let controller = UIAlertController(title: "No Internet Detected", message: "This app requires an Internet connection", preferredStyle: .alert)
let ok = UIAlertAction(title: "OK", style: .default, handler: nil)
let cancel = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
controller.addAction(ok)
controller.addAction(cancel)
present(controller, animated: true, completion: nil)
}
Auth.auth().addStateDidChangeListener{ auth, user in
if Auth.auth().currentUser != nil {
let vc = self.storyboard?.instantiateViewController(withIdentifier: "deyaPay")as!deyaPay
//self.present(vc, animated: true, completion: nil)
let navigationController = UINavigationController(rootViewController: vc)
self.present(navigationController, animated: true, completion: nil)
} else {
print("signout")
}
}
}
}