0

AFJSONRequestOperation を使用する関数があり、成功した場合にのみ結果を返したいと考えています。正しい方向に私を向けることができますか?特にブロックと AFNetworking については、まだ少し無知です。

4

1 に答える 1

0

コードを投稿しておけばよかった

使用__blockすると、ブロック内で変数を使用できます

__block NSString *msg;
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation  setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
        [hud hide:YES];
        NSLog(@"Success %@",  operation.responseString);
        NSDictionary *message = [NSJSONSerialization JSONObjectWithData:[operation.responseString dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"%@",message);
        msg = message
        ALERT(@"Posted", message[@"message"]);
    }
                                      failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                                          NSLog(@"error: %@",  operation.responseString);
                                          NSLog(@"%@",error);
                                      }];
    [operation start];
于 2013-11-15T07:44:47.217 に答える