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 回答