我正在寻找帮助关闭createuser vc并返回上一个初始vc,如果用户在firebase中的alreadyexists。
我目前有:
// 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之前选择解除,这也是有用的。
由于
答案 0 :(得分:0)
问题解决了,如果有人对此感兴趣,那么我是如何解决问题的:
System.out.println("Please enter an initial deposit:");
try{
deposit.add(keyboard.nextInt());
}catch(NumberFormatException e){
System.out.println("Invalid input");
System.out.println("Please enter an account number:");
accountNumber.add(keyboard.nextDouble());