Start a new topic

Alerts are disappearing when involving KCSUser

I am somewhat new to XCode, and this might not be Kinvey related. However, it seems like it might be, as I was able to get it to work in Parse. The following is a code snippet. 

        // Check if passwords match
        if password! != passwordConfirm! {
            AlertViewController.displayAlert(
                "Passwords do not match",
                viewController: self)
            return
        }
        
        // Check if user exists
        KCSUser.checkUsername(email!,
            withCompletionBlock: {(
                email: String!,
                emailAlreadyTaken: Bool,
                error: NSError!) -> Void in
                    if userExists == 0 {
                        AlertViewController.displayAlert(
                            "Email already taken",
                            viewController: self)
                        return
                    }
            }
        )

The problem is that, if I enter two different passwords in my sign up view, it will display an alert, and allow me to click dismiss. Once I click dismiss, it just dismisses the alert view, and I'm able to continue editing fields. This works as intended. Now if I enter credentials that should trigger an existing user, something odd happens. If I have more code after the block that checks an existing user, that code will continue. It will be as if the alert never happened. But it does happen, because if I display another alert, it will tell me in the console that it attempted to load a view while another was deallocating. So it's basically ignoring the return call.


Any help? Thank you.


Sorry, that part should be 

if emailAlreadyTaken {...}

 How do I edit my post even?

George,


Can you please post the updated code?  if emailAlreadyTaken == 0  {...} 

would be testing for if the email is NOT already taken, since 0 is false in boolean logic and 1 is true.  


Can you please reupload your code and we'll look at it when we get a chance?


Thanks,

Yes of course, but how do I edit my original post?

I don't believe that you can.  You can just make another post in this thread, it will be fine.


Thanks,

Sorry for the late reply. I've been really busy. Haven't had time to play around with my code.


 

        // Check if passwords match
        if password! != passwordConfirm! {
            AlertViewController.displayAlert(
                "Passwords do not match",
                viewController: self)
            return
        }
        
        // Check if user exists
        KCSUser.checkUsername(email!,
            withCompletionBlock: {(
                email: String!,
                emailAlreadyTaken: Bool,
                error: NSError!) -> Void in
                    if emailAlreadyTaken {
                        AlertViewController.displayAlert(
                            "Email already taken",
                            viewController: self)
                        return
                    }
            }
        )

 I actually noticed that if I use code from the Kinvey guide exactly as is, it will work properly. However, the code in the guide is deprecated, and I hear it is not good to use deprecated functions.

Login or Signup to post a comment