【问题标题】:How manipulate Block Objective C in AFNetworking?如何在 AFNetworking 中操作 Block Objective C?
【发布时间】:2014-03-05 14:15:28
【问题描述】:

我要做的是:我的class1(称为方法,需要llamda)->class2(也称为方法并等待调用)->class3(最近这个类查询JBoss服务器AFNetworking)。并使用方法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 根据响应执行一些操作。

我该如何解决这个问题?

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 并返回结果,但结果是块:

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;
  }];
}

已经尝试了我想的一切。有人可以解释一下我如何解决这个问题。谢谢

【问题讨论】:

    标签: objective-c block objective-c-blocks afnetworking-2


    【解决方案1】:

    试试这个:

    manager.operationQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    

    【讨论】:

    • 这些是做什么的?以及如何使用?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-08
    • 1970-01-01
    • 1970-01-01
    • 2018-01-28
    相关资源
    最近更新 更多