简体   繁体   English

等待直到AFJSONRPCClient请求中的完成块未完成

[英]wait until completion block not finished in AFJSONRPCClient request

i am new in IOS and i need your help. 我是IOS的新手,需要您的帮助。 Here is my code. 这是我的代码。

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

i want wait until the response not getting. 我想等到响应没有收到。

You should use a delegate. 您应该使用一个委托。 Call it when you get a response. 收到回复后调用它。

Try to use completion handler block like this: 尝试使用完成处理程序块,如下所示:

    - (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();
          }});
      });
    }

To call this: 调用此:

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

Hope it will help you. 希望对您有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM