【发布时间】:2013-04-22 16:48:31
【问题描述】:
奇怪的标题,我知道,但这是解释我的问题的最快方法。 Parse 服务有一个预建的注册控制器,用于让新用户注册您可能拥有的任何服务。无法编辑它的实现,您只能在它的委托方法中处理事件。所以我不能把它放在“注册”按钮的 IBAction 中。我想要做的是,当用户触摸“注册”时,我需要调用一些 API 来检查是否存在某些东西,然后如果它已经存在,那么不要让用户签名向上。这是用于在按下按钮时处理验证的委托方法:
// Sent to the delegate to determine whether the sign up request should be submitted to the server.
- (BOOL)signUpViewController:(PFSignUpViewController *)signUpController shouldBeginSignUp:(NSDictionary *)info {
这是我想要放入其中的内容:
[self processJSONDataWithURLString:[NSString stringWithFormat:@"https://www.someapi.com/api/profile.json?username=%@",username] andBlock:^(NSData *jsonData) {
NSDictionary *attributes = [jsonData objectFromJSONData];
// Check to see if username has data key, if so, that means it already exists
if ([attributes objectForKey:@"Data"]) {
return NO; // Do not continue, username already exists
// I've also tried:
dispatch_sync(dispatch_get_main_queue(), ^{ return NO; } );
}
else
return YES; //Continue with sign up
dispatch_sync(dispatch_get_main_queue(), ^{ return YES; } );
}];
但是,当我尝试返回任何内容时,我会遇到错误。当我直接返回 YES 时,“^(NSData *jsonData)”带有黄色下划线,并且我得到“不兼容的块指针类型将 BOOL (^)NSData *_strong 发送到 void(^)NSData 类型的参数*_strong”。
基本上,有什么方法可以在此方法中调用 API 来检查某些内容,然后根据结果返回 YES 或 NO?
谢谢!
【问题讨论】:
-
为什么需要 dispatch_sync(dispatch_get_main_queue()^ 两次???
标签: ios parsing delegates objective-c-blocks