Signing up to app takes too long and pauses

For some reason when I sign up a new user, the progressHud appears, then disappears, then it takes up to 4-5 seconds before moving on to the next view. It seems like something is off because from a users perspective it looks like the app is frozen. Is there any way to fix this or does it normally take up to 5 seconds for signing up into firebase?

func signUP(firstLastName: String, email: String, location: String, biography: String, password: String, interests: String, pictureData: NSData!) {

    Auth.auth().createUser(withEmail: email, password: password) { (user, error) in
        if error == nil, let unwrappedUser = user{

            self.setUserInfo(firstLastName: firstLastName, user: unwrappedUser, location: location, interests: interests, biography: biography, password: password, pictureData: pictureData)

        }

        else{
            print(error?.localizedDescription)
        }
    }

}
func getLocationFromPostalCode(postalCode : String, completion:@escaping (String?) -> Void) {
    let geocoder = CLGeocoder()

    geocoder.geocodeAddressString(postalCode) {
        (placemarks, error) -> Void in
        // Placemarks is an optional array of type CLPlacemarks, first item in array is best guess of Address

        if let placemark = placemarks?.first {

            if placemark.postalCode == postalCode {
                // you can get all the details of place here
                print("\(placemark.locality)")
                print("\(placemark.country)")
                completion(placemark.locality)
                return
            }
            else{

                print("Please enter valid zipcode")
            }
        }
        completion(nil)

    }
}
func submitPressed(){

    var pictureD: Data? = nil
    if let imageView = self.sentPic.image{
        pictureD = UIImageJPEGRepresentation(imageView, 0.2)
    }
    let nameText = name
    let interests = options.joined(separator: ", ")

    let emailField = email.lowercased()
    let finalEmail = emailField.trimmingCharacters(in: .whitespacesAndNewlines)
    let biography = bioTextView.text!
    let passwordText = password
    if  finalEmail.isEmpty || biography.isEmpty || password.isEmpty || interests.isEmpty || pictureD == nil {
        self.view.endEditing(true)
        let alertController = UIAlertController(title: "Low Blow", message: " You must fill all the fields.", preferredStyle: .alert)
        alertController.addAction(UIAlertAction(title: "OK", style: .cancel, handler: nil))
        present(alertController, animated: true, completion: nil)
    }else {

         SVProgressHUD.show()
        getLocationFromPostalCode(postalCode: zipCode) { (location) in
            self.view.endEditing(true)
            self.authService.signUP(firstLastName: nameText, email: finalEmail, location: location ?? "Unknown", biography: biography, password: self.password, interests: interests, pictureData: pictureD! as NSData)

        }

        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let vc = storyboard.instantiateViewController(withIdentifier: "NewTabBarViewController") as! UIViewController
    }
     SVProgressHUD.dismiss()

}

2 answers

  • answered 2018-02-13 00:39 Joe - New Nine

    You don't show enough code here, but I'm guessing that your Firebase signup is in authService.signUP. Our experience with Firebase is about 20ms - 500ms tops, so I'm guessing your lag is coming from that plus whatever is going on in getLocationFromPostalCode (which is maybe calling a different api to get lat/lon?)

    If that's true, I'd suggest a small edit - getLocationFromPostalCode as soon as the postal code is entered. That way, the user can finish the registration while that's happening in the background. Worst case scenario, you'll reduce the lag time because you're not asking the user to wait for both calls.

  • answered 2018-02-13 02:13 eLillie

    From a user experience perspective, if you're ok with a 5 second delay so long as your progressHUD is still showing, just move the SVProgressHUD.dismiss call to the last completion block you expect to execute.

    From what I can see, that would be in the completion block of Auth.auth().createUser, though if there is further work being done in setUserInfo, you should move it to the innermost callback in there.