ios - swift closing a vc controller from within a FIREBASE_REF block -


i'm looking assistance in closing createuser vc , returning previous initial vc if user alreadyexists in firebase.

i have :

// attempt create new user.  (authdata = dictionary).         firebase_ref.createuser(email, password: password, withvaluecompletionblock: { (error, authdata) in  // if there no error             if error == nil { // authorise new user application.  (authdata = object).                 firebase_ref.authuser(email, password: password, withcompletionblock: { ( error, authdata) in                      if error == nil { // store user id device.                         nsuserdefaults.standarduserdefaults().setvalue(authdata.uid, forkey: "uid") // stop activity indicator.                         self.activityind.stopanimating() // close create user screen.                         self.dismissviewcontrolleranimated(true, completion: nil)                     }                     else                     { // stop activity indicator.                         self.activityind.stopanimating()                          print(error)                     }                 })             }             else  // user account exists \\             { // stop activity indicator.                 self.activityind.stopanimating()  // display error message.                 let alertcontroller = uialertcontroller(title: "user duplication error", message:                     "user account exists, login normal", preferredstyle: uialertcontrollerstyle.alert)                 alertcontroller.addaction(uialertaction(title: "dismiss", style: uialertactionstyle.default,handler: nil))                 self.presentviewcontroller(alertcontroller, animated: true, completion: nil)  // close create user screen.                 self.dismissviewcontrolleranimated(true, completion: nil)              }       }) 

when user creates new account self.dismissviewcontroller works fine , returns initial vc , loads homepage. however, when there existing user self.dismissviewcontroller doesn't anything. if can shed light on appreciated.

also, if can advise on how ensure alert message stays on screen until user selects dismiss before closing vc helpful too.

thanks

problem solved, if interested heres how got round issue:

// user account exists \\             { // stop activity indicator.                 self.activityind.stopanimating()  // display error message.                 let refreshalert = uialertcontroller(title: "user duplication error", message: "user account exists, login normal.", preferredstyle: uialertcontrollerstyle.alert)                  refreshalert.addaction(uialertaction(title: "dismiss", style: .default, handler: { (action: uialertaction!) in // close create user screen.                     self.dismissviewcontrolleranimated(true, completion: nil)                 }))                  self.presentviewcontroller(refreshalert, animated: true, completion: nil)             }       }) 

Comments