等到完成块未在AFJSONRPCClient请求中完成

时间:2014-12-15 07:20:45

标签: ios objective-c iphone

我是IOS的新手,我需要你的帮助。 这是我的代码。

AFJSONRPCClient *client = [AFJSONRPCClient clientWithEndpointURL:[NSURL URLWithString:url]];
[client invokeMethod:@"call" success:^(AFHTTPRequestOperation *operation, id responseObject){
        NSLog(@"response %@",responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *err){
        NSLog(@"errr  %@",[err description]);
    }];

我想等到答复没有到来。

2 个答案:

答案 0 :(得分:1)

您应该使用委托。当你得到回复时,请打电话。

答案 1 :(得分:0)

尝试使用完成处理程序块,如下所示:

    - (void)doProcess_With_Comp:(void (^)(void))completion{
      dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        // Add Your process here
        AFJSONRPCClient *client = [AFJSONRPCClient clientWithEndpointURL:[NSURL URLWithString:url]];
        [client invokeMethod:@"call" success:^(AFHTTPRequestOperation *operation, id responseObject){
        NSLog(@"response %@",responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *err){
        NSLog(@"errr  %@",[err description]);
    }];
        dispatch_async(dispatch_get_main_queue(), ^{
          if (completion) {
            completion();
          }});
      });
    }

打电话给:

[self doProcess_With_Comp:^{
  NSLog(@"Process Completed");}];

希望它会对你有所帮助。

相关问题