1

我仍在尝试掌握objective-c 和AFNetworking。我在 mysql 后端做一个 POST(通过 UI 按钮),它返回一个 json 响应。我可以看到下载进度,但我的成功和失败块永远不会被调用。下面的代码片段。我只看到打印出来的 1 和 4。

    NSMutableURLRequest *apiRequest = [self multipartFormRequestWithMethod:@"POST" path:kAPIPath parameters:params constructingBodyWithBlock:^(id <AFMultipartFormData>formData) {

     NSLog(@"Success in calling");
     }];

     AFHTTPRequestOperation* operation = [[AFJSONRequestOperation alloc] initWithRequest: apiRequest];
     NSLog(@"1");
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        //success!
        NSLog(@"Response: %@", [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding]);
        NSLog(@"2");
        completionBlock(responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        //failure :(
        NSLog(@"3");
        completionBlock([NSDictionary dictionaryWithObject:[error localizedDescription] forKey:@"error"]);
    }];
    });
     NSLog(@"4");

    [operation start];

[operation setDownloadProgressBlock:^( NSUInteger bytesRead , long long totalBytesRead , long long totalBytesExpectedToRead )
     {
         NSLog(@"%lld of %lld", totalBytesRead, totalBytesExpectedToRead);
     }
     ];
4

0 回答 0