我已经将我的应用程序与解析框架集成,并在注册过程中添加了一些额外的字段,其中一个是电话号码。 我想检查以确保输入的电话号码在被允许注册之前是唯一的,就像解析用户名和电子邮件一样。 但是,我无法在任何地方找到有关如何操作的文档。
我已经尝试在PFUser上运行查询以检查输入的电话号码是否在Users表中,但查询将不起作用(结果总是为nil),除非它包含在signUpInBackgroundWithBlock代码中。 但是,无论查询结果如何,在此处放置查询仍会上传要解析的信息。 有没有人找到办法做到这一点? 提前致谢!
I've integrated my app with the parse framework and have added a few extra fields during the sign up process, one of those being phone number. I'd like to check to make sure the phone number entered is unique prior to them being allowed to sign up, like parse does for username and email. However, I can't find documentation anywhere on how to do so.
I've tried running a query on PFUser to check if the entered phone number is in the Users table but the query won't work (results are always nil) unless its included in the signUpInBackgroundWithBlock of code. However, putting the query here still uploads the info to parse no matter the results of the query. Has anyone found a way to do this? Thanks in advance!
最满意答案
如果您分享您的查询会有所帮助,但类似下面的内容应该可以解决问题:
PFQuery *query = [PFQuery queryWithClassName:@"User"]; [query whereKey:@"phoneNo" equalTo:@"0123456"]; [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { if (!error) { // The find succeeded. if (objects.count == 0) { //Allow Number to be saved } else { //Give warning that the number is already in use } } else { // Log details of the failure NSLog(@"Error: %@ %@", error, [error userInfo]); } }];}
Would be helpful if you share your query but something like the following should probably do the trick:
PFQuery *query = [PFQuery queryWithClassName:@"User"]; [query whereKey:@"phoneNo" equalTo:@"0123456"]; [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { if (!error) { // The find succeeded. if (objects.count == 0) { //Allow Number to be saved } else { //Give warning that the number is already in use } } else { // Log details of the failure NSLog(@"Error: %@ %@", error, [error userInfo]); } }];}
更多推荐
发布评论