我仍然试图抓住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);
}
];