奇怪的標題,我知道,但這裏是解釋我的問題的最快方法。 Parse服務有一個預先建立的註冊控制器,讓新用戶註冊您可能擁有的任何服務。沒有辦法編輯它的實現,你只能在它的委託方法中處理事件。所以我不能把它放在「註冊」按鈕的IBAction中。我想要做的是,當用戶觸摸「註冊」時,我需要調用某個API來檢查是否存在某個事件,如果它已經存在,則不要讓用戶簽名向上。這裏是指處理驗證時,按下按鈕時的委託方法:是否可以在返回BOOL的委託方法中執行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 * _ 強發送void參數類型(^)NSData * _強大」。
基本上,有什麼辦法可以在這個方法中進行API調用來檢查某些內容,然後根據結果返回YES或NO?
謝謝!
爲什麼你需要dispatch_sync(dispatch_get_main_queue()^兩次??? – satheeshwaran 2013-04-22 18:16:43