AFNetworking,AFHTTPRequestOperation完成块缓慢触发代码

iam*_*mug 9 iphone ios5 afnetworking

我正在使用AFNetworking注册新用户,一切正常,但在下面的块我有一些问题:

    AFHTTPRequestOperation *operation = [[[AFHTTPRequestOperation alloc] initWithRequest:myRequest] autorelease];
operation.completionBlock = ^ {
    if ([operation hasAcceptableStatusCode]) {
        NSLog(@"success");
        username.backgroundColor = [UIColor yellowColor];
    } else {
        switch ([operation.response statusCode]) {
            case 421:                  
            {
                NSLog(@"Username taken.");
                username.backgroundColor = [UIColor yellowColor];   
            }
                break;
            default:
                break;
        }
    }
};
Run Code Online (Sandbox Code Playgroud)

基本上我的服务器端脚本做了一些验证并激活了HTTP状态代码(我知道421不是有效的).这使我能够知道服务器上出了什么问题,这很有效.

我的问题是,当响应返回它触发的NSLog(@"success");NSLog(@"Username taken.");直线距离,但相当多的几秒钟,任何其他代码火灾后.

有人可以对此有所了解吗?

iam*_*mug 32

这是我的问题的解决方案,这是更好,更快的地狱:

AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]initWithRequest:request];
[operation  setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {

    NSLog(@"success: %@", operation.responseString);

    [SVProgressHUD dismissWithSuccess:@"Sucess!" afterDelay:2];
    [self saveContinue:operation.responseString];


} 
    failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"error: %@",  operation.responseString);

}
 ];
Run Code Online (Sandbox Code Playgroud)

我希望这有助于人们.