如何在AFNetworking中操纵块目标C? [英] How manipulate Block Objective C in AFNetworking?
问题描述
我的工作是:我的class1(称为方法,并且期望llamda)-> class2(也称为方法并等待调用)-> class3(最近该类查询JBoss服务器AFNetworking).并使用方法AFNetworking:
What I do is this: My class1 (called a method, and expects llamda) -> class2 (also called a method and waiting for a call) -> class3 (recently this class queries the JBoss server AFNetworking) . And use the method AFNetworking:
- (AFHTTPRequestOperation *) POST: (NSString *) URLString
parameters: (NSDictionary *) parameters
constructingBodyWithBlock: (void (^) (id <AFMultipartFormData> FormData)) block
success: (void (^) (* AFHTTPRequestOperation operation, responseObject id)) success
failure: (void (^) (* AFHTTPRequestOperation operation, NSError * error)) failure;
如果或何时响应返回我一个阻止.而这个答案我自己需要返回到class2,并从class1返回到class2.然后class1根据响应执行一些操作.
And if or when the response returns me a block. And that answer myself need to return to the class2 and class1 to class2. And class1 performs some action according to the response.
我该如何解决?
Classes1 Method:
- (IBAction)pressedButton_createdUser:(id)sender
{
NSString * language = [[NSLocale preferredLanguages] objectAtIndex:0];
NSDictionary *resultDict = [_mainViewController.restServices newUserNewDevice:xxx
email:xxx
password:xxx
name:xxx
surname:xxx
phonenumber:xxx
currentLanguageCode:xxx
isNewBusiness:xxx
nameOrCode:xxx];
NSLog(@"%@",[resultDict objectForKey:@"response"]);
}
Classes2 Methods Call:
- (NSDictionary *)newUserNewDevice:(UIImage *)photo email:(NSString *)email password:(NSString *)password name:(NSString *)name surname:(NSString *)surname phonenumber:(NSString *)phonenumber currentLanguageCode:(NSString *)currentLanguageCode isNewBusiness:(BOOL)isNewBusiness nameOrCode:(NSString *)nameOrCode
{
[_webservicesTask addParams:TAG_PHOTO Object:dataPhoto];
.
.
[_webservicesTask addParams:TAG_NAME_OR_CODE Object:nameOrCode];
[_webservicesTask executeMultipart:userRestPath]];
return [json objectWithString:_strResult];
}
最后,此类使用AFNetworking并返回结果,但结果位于块中:
And finally this class use AFNetworking and return result, but result in block:
classes3
- (void)executeMultipart:(NSString *)url
{
[_operationManager POST:url parameters:_params
constructingBodyWithBlock:^(id<AFMultipartFormData> formData){
[formData appendPartWithFormData:(NSData *)[_params objectForKey:TAG_PHOTO] name:TAG_PHOTO];
} success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"%@",operation.responseString);
NSString *strJSON = [operation.responseString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
_objREST.strResult = strJSON;
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"%@",operation.responseString);
NSString *strJSON = [operation.responseString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
_objREST.strResult = strJSON;
}];
}
我已经尝试了一切.有人可以解释一下我如何解决这个问题.谢谢
Already tried everything I think. Can someone please explain me how I can solve this problem. Thanks
推荐答案
尝试一下:
manager.operationQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
这篇关于如何在AFNetworking中操纵块目标C?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!