簡體   English   中英

等待直到AFJSONRPCClient請求中的完成塊未完成

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

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

我想等到響應沒有收到。

您應該使用一個委托。 收到回復后調用它。

嘗試使用完成處理程序塊,如下所示:

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

希望對您有幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM