i am creating a Swift
app and with this app user can login with their email so for that i have created webservice and user can able to login successfully but after login when i got success response i am redirecting back to Home screen of app but pushViewController
not working i am getting below error
pushViewController:animated: called on while an existing transition or presentation is occurring; the navigation stack will not be updated.
below is my code for login with api integration and redirecting code
let params = ["email":txtEmail.text!,"password":txtPassword.text! ,"device_type":"iOS" , "device_token": deviceid]
print(params)
self.viewMainSpinner.isHidden = false
self.viewInnerSpinner.startAnimating()
Alamofire.request(login, method: .post, parameters: params).responseJSON(completionHandler: {(response) in
print(response.result)
switch response.result{
case.success(let value):
let json = JSON(value)
let success = json["success"].stringValue
if success == "1"{
let message = json["message"].stringValue
let data = json["data"]
let accesstkn = data["access_token"].stringValue
let userid = data["user_id"].stringValue
let firstName = data["first_name"].stringValue
let preferences = UserDefaults.standard
let uid = "u_id"
let acctkn = "acc_tkn"
let f_name = "first_name"
let u_id = userid
let acc_tkn = accesstkn
let firName = firstName
preferences.set(u_id, forKey: uid)
preferences.set(acc_tkn, forKey: acctkn)
preferences.set(firName, forKey: f_name)
Loaf(message, state: .success, sender: self).show()
let storyboard = UIStoryboard(name: "Functional", bundle: nil)
let VC = storyboard.instantiateViewController(withIdentifier: "CustomTabBarViewController") as! CustomTabBarViewController
self.navigationController?.interactivePopGestureRecognizer?.isEnabled = false
self.navigationController?.pushViewController(VC, animated: true)
}else{
let message = json["message"].stringValue
Loaf(message, state: .error, sender: self).show()
}
case.failure(let error):
Loaf(error.localizedDescription, state: .error, sender: self).show()
}
self.viewMainSpinner.isHidden = true
self.viewInnerSpinner.stopAnimating()
})
please check here is my login code and after login i am not able to redirect on home screen
please tell me why this is happing ?
Seem like show()
method implementation is performing navigation related action in below line of code:
Loaf(message, state: .success, sender: self).show()
and quickly after that you are performing push on navigation controller.
Try commenting above line of code and try to login.