Swift UIButton click,Alamofire POST call,在Firebase登录成功时不会执行检查
我有一个简单的按钮动作 我确实在进入之前验证了电子邮件和密码,但这是我的Firebase代码。当您单击按钮时,它将进入Swift UIButton click,Alamofire POST call,在Firebase登录成功时不会执行检查,swift,alamofire,Swift,Alamofire,我有一个简单的按钮动作 我确实在进入之前验证了电子邮件和密码,但这是我的Firebase代码。当您单击按钮时,它将进入VerifyUserInformation功能,并将弹出响应。基本上,segue的inVerifyUserInformation不会为我运行,dismise函数也不会关闭模式(显示全屏) 如何解决这个问题 Auth.auth().signIn(withEmail: emailOutlet.text!, password: passwordOutlet.text!)
VerifyUserInformation
功能,并将弹出响应。基本上,segue的inVerifyUserInformation
不会为我运行,dismise函数也不会关闭模式(显示全屏)
如何解决这个问题
Auth.auth().signIn(withEmail: emailOutlet.text!, password: passwordOutlet.text!) { [weak self] user, error in
guard let strongSelf = self else { return }
if let error = error {
self!.displaySnackbar(messageString: "\(error.localizedDescription)")
return
}
self!.preferences.setValue(true, forKey:SHARED_PREF_USER_LOGGED_IN_KEY)
var firstTimeUser = self!.preferences.bool(forKey:FIRST_TIME_USER)
print("\(self!.TAG) FirstTimeUser: \(firstTimeUser)")
if (firstTimeUser) {
print("\(self!.TAG) This is the first time the user is using the application.")
self?.VerifyUserInformation(firebaseId: "\(Auth.auth().currentUser!.uid)")
} else {
print("\(self!.TAG) User can head into the Application.")
self!.performSegue(withIdentifier: "MainScreen", sender: nil)
self?.progressBar.isHidden = true
self!.loginButtonOutlet.isHidden = false
}
}
为了验证用户,我运行了这个函数
func VerifyUserInformation(firebaseId: String) {
let urlString = ADD_USER_FOR_ACCOUNT
let param = [
FROM_APP: "true",
USER_FIREBASE_ID: firebaseId,
GET_USER_ACCOUNT_INFORMATION: "true"
] as [String : Any]
AF.request(urlString, method: .post, parameters: param ,encoding: URLEncoding.default).responseJSON {
response in
switch response.result {
case .success:
print("\(self.TAG)\n***Response***\n\(response)\n***END***")
if let result = response.value {
let JSON = result as! NSDictionary
let errorResponse = JSON["error"] as! Int
if (errorResponse == 1) {
print("\(self.TAG) Error verifying the user.")
self.displaySnackbar(messageString: "Error verifying user. Try again.")
} else {
print("\(self.TAG) User is verified")
let messageResponse = JSON["message"] as! String
if (messageResponse == "user has items") {
print("\(self.TAG) User has items, go into MainScreen")
DispatchQueue.main.async {
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
self.performSegue(withIdentifier: "MainScreen", sender: nil)
self.dismiss(animated: false, completion: nil)
self.preferences.setValue(false, forKey:FIRST_TIME_USER)
self.loginButtonOutlet.isHidden = false
self.progressBar.isHidden = true
}
}
} else {
print("\(self.TAG) User has 0 items, go into Second Onboarding")
DispatchQueue.main.async {
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
self.performSegue(withIdentifier: "SecondOnBoarding", sender: nil)
self.dismiss(animated: false, completion: nil)
self.loginButtonOutlet.isHidden = false
self.progressBar.isHidden = true
}
}
}
}
}
break
case .failure(let error):
self.loginButtonOutlet.isHidden = false
self.progressBar.isHidden = true
self.displaySnackbar(messageString: "Error getting user information. Try again.")
print("\(self.TAG) \(error)")
}
}
}
删除
dismise()
后,它开始工作。您可以发布AF
请求的printDebug(result)
结果吗?