简体   繁体   English

在当前线程(signUp :)上执行Parse.com用户注册并检索NSError

[英]perform Parse.com user signup on the current thread (signUp:) and retrieving the NSError

I have to call Parse's user signUp method on the current thread, not the background thread as it's already being called on the background thread. 我必须在当前线程上调用Parse的用户signUp方法,而不是在后台线程上调用,因为已经在后台线程上调用了它。 The -(BOOL)signUp method isn't good enough as I only get a BOOL response if the registration was successful or not, but I have to handle the potential errors. -(BOOL)signUp方法还不够好,因为如果注册成功与否,我只会得到BOOL响应,但是我必须处理潜在的错误。

I've noticed the method -(BOOL)signUp:(NSError **)error but my current iOS programming skills as not there yet when it comes to understanding how to use it :) 我注意到方法-(BOOL)signUp:(NSError **)error但是在了解如何使用它时,我目前的iOS编程技能还不存在:)

Here is the signUp: documentation 这里是注册:文档

I've tried adding an extra property to my user object called NSError *latestError and I was hoping to call the mentioned method and put the NSError returned into that value so I can handle errors on the main thread: 我尝试向我的用户对象添加一个名为NSError * latestError的额外属性,我希望调用上述方法并将NSError返回到该值中,以便我可以处理主线程上的错误:

-(BOOL)registerUser{
    PFUser *newUser = [PFUser user];
    newUser.username = self.username;
    newUser.password = self.password;
    return [newUser signUp:self.lastError]; // error
}

but I get this error: 但是我得到这个错误:

Implicit conversion of an Objective-C ponter to 'NSError *__autoreleasing *' is disallowed with ARC ARC不允许将Objective-C响应器隐式转换为“ NSError * __ autoreleasing *”

Any ideas how to make it work with this method or alternative ways to achieve the same result? 有什么想法如何使它与这种方法或替代方法一起使用以实现相同的结果?

You have to pass a reference to a NSError object.. Parse will do the process and if any error is there it will update the error object with appropriate error. 您必须传递对NSError对象的引用。解析将执行该过程,并且如果存在任何错误,它将使用适当的错误更新错误对象。

You new code should be like 你的新代码应该像

-(BOOL)registerUser{
    NSError *error = nil;
    PFUser *newUser = [PFUser user];
    newUser.username = self.username;
    newUser.password = self.password;
    [newUser signUp:&error]; // error

    if( error != nil)
    {
      //log the error or show alert
      return NO;
    }

    return YES;


}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM