Parse.com PFUser signUpInBackgroundWithBlock:第一次点击时未调用块 [英] Parse.com PFUser signUpInBackgroundWithBlock: block not being called on first tap

查看:81
本文介绍了Parse.com PFUser signUpInBackgroundWithBlock:第一次点击时未调用块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Swift和parse.com框架开发iOS应用程序,并且在注册新用户方面遇到很大的问题.

i am developing an iOS-App with Swift and the parse.com framework and have a big problem with registering new users.

尽管正在注册新用户,但第一次点击时不会调用"signUpInBackgroundWithBlock"块.当我第二次点击按钮时,该块最终被调用,并且我得到一个错误,该用户名已被注册.

The block of "signUpInBackgroundWithBlock" is not being called on the first tap, although the new user is getting registered. When i am tapping the button a second time, the block gets finally called and i get an error, that the username is already registered.

var newUser = PFUser()
newUser.username = registerView.nicknameTextField.text.trim()
newUser.email = registerView.emailTextField.text
newUser.password = registerView.passwordTextField.text

newUser.signUpInBackgroundWithBlock {
        (succeeded: Bool, error: NSError!) -> Void in
            self.registerCompletionBlock(succeeded, error: error)
    }

有人遇到相同的问题,并且知道解决此奇怪行为的方法吗?

Is someone having the same problem and knows a solution for this strange behaviour?

谢谢!

完成块应调用"registerCompletionBlock()"函数:

The completion block should call the "registerCompletionBlock()" function:

func registerCompletionBlock(succeeded: Bool, error: NSError!) {
    if error == nil {
        let subscriptionStoryboard = UIStoryboard(name: "Subscription", bundle: nil)
        let viewcontroller: UIViewController = subscriptionStoryboard.instantiateInitialViewController() as UIViewController
        self.presentViewController(viewcontroller, animated: true, completion: nil)
    } else {
        if let errorString = error.userInfo?["error"] as? NSString {
            println(errorString)
            if error.userInfo?["code"] as Float == 202{
                let alert = UIAlertView(title: "vergeben", message: "name vergeben", delegate: nil, cancelButtonTitle: "abbrechen")
                alert.show()
            }
        }
    }
}

推荐答案

我尝试了先前发布的解决方案(消除了PFUser.enableAutomaticUser()),问题仍然存在.

I tried the solution posted previously (eliminating PFUser.enableAutomaticUser()), and the issue persisted.

如果其他任何人仍在寻找解决此问题的方法,请尝试在signUpInBackground块中将if error == nil更改为if succeeded == true.这对我有用,并且所有功能都在后端运行.

In case anyone else is still looking for a solution to this issue, try changing the if error == nil to if succeeded == true in the block of signUpInBackground. This worked for me and all is functional in backend.

这篇关于Parse.com PFUser signUpInBackgroundWithBlock:第一次点击时未调用块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆