如果用户已存在于 firebase 中,我只是在关闭 createuser vc 并返回到之前的初始 vc 方面寻求帮助。
我目前有:
// Attempt to create a new user. (authData = dictionary).
FIREBASE_REF.createUser(email, password: password, withValueCompletionBlock: { (error, authData) in
// If there was no error then
if error == nil {
// Authorise the new user into the application. (authData = object).
FIREBASE_REF.authUser(email, password: password, withCompletionBlock: { ( error, authData) in
if error == nil {
// Store the user id into the device.
NSUserDefaults.standardUserDefaults().setValue(authData.uid, forKey: "uid")
// Stop the activity indicator.
self.activityInd.stopAnimating()
// Close the create user screen.
self.dismissViewControllerAnimated(true, completion: nil)
}
else
{
// Stop the activity indicator.
self.activityInd.stopAnimating()
print(error)
}
})
}
else
// USER ACCOUNT ALREADY EXISTS \\
{
// Stop the activity indicator.
self.activityInd.stopAnimating()
// Display an error message.
let alertController = UIAlertController(title: "USER DUPLICATION ERROR", message:
"user account already exists, login as normal", preferredStyle: UIAlertControllerStyle.Alert)
alertController.addAction(UIAlertAction(title: "Dismiss", style: UIAlertActionStyle.Default,handler: nil))
self.presentViewController(alertController, animated: true, completion: nil)
// Close the create user screen.
self.dismissViewControllerAnimated(true, completion: nil)
}
})
当用户创建一个新帐户时,self.dismissViewController 工作得很好,并返回到初始 vc,然后加载主页。但是,当已有用户时, self.dismissViewController 不会执行任何操作。如果有人能对此有所了解,我们将不胜感激。
此外,如果有人可以建议如何确保警报消息保留在屏幕上,直到用户在关闭 vc 之前选择关闭,这也会有所帮助。
谢谢
最佳答案
问题已解决,如果有人感兴趣的话,我是如何解决这个问题的:
// USER ACCOUNT ALREADY EXISTS \\
{
// Stop the activity indicator.
self.activityInd.stopAnimating()
// Display an error message.
let refreshAlert = UIAlertController(title: "USER DUPLICATION ERROR", message: "user account already exists, login as normal.", preferredStyle: UIAlertControllerStyle.Alert)
refreshAlert.addAction(UIAlertAction(title: "Dismiss", style: .Default, handler: { (action: UIAlertAction!) in
// Close the create user screen.
self.dismissViewControllerAnimated(true, completion: nil)
}))
self.presentViewController(refreshAlert, animated: true, completion: nil)
}
})
关于ios - 快速从 FIREBASE_REF block 内关闭 vc Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36236380/