您好我正在尝试编译以下代码,但收到错误Use of undeclered identifier AFHTTPClient
:
NSData* fileNameData = [fileName dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *sendDictionary =
[NSDictionary dictionaryWithObject:fileNameData forKey:@"fileName"];
AFHTTPClient *httpClient =
[[AFHTTPClient alloc] initWithBaseURL:@"http://www.olcayertas.com"];
NSMutableURLRequest *afRequest =
[httpClient multipartFormRequestWithMethod:@"POST"
path:@"/photos"
parameters:sendDictionary
constructingBodyWithBlock:^(id <AFMultipartFormData>formData) {
[formData appendPartWithFileData:photoImageData
name:self.fileName.text
fileName:filePath
mimeType:@"image/jpeg"];
}];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:afRequest];
[operation setUploadProgressBlock:^(NSInteger bytesWritten, NSInteger totalBytesWritten, NSInteger totalBytesExpectedToWrite) {
NSLog(@"Sent %d of %d bytes", totalBytesWritten, totalBytesExpectedToWrite);
}];
[operation setCompletionBlock:^{
//NSLog(@"%@", operation.responseString); //Gives a very scary warning
}];
[operation start];
我正在使用CocoaPods,这是我的pod文件:
platform :ios, '7'
pod 'AFNetworking', '~> 2.0'
pod 'AFNetworking/NSURLSession', '~> 2.0'
答案 0 :(得分:10)
您正在使用AFNetworking 2.0,但2.0中不存在AFHTTPClient
- 这是1.0功能。检查migration guide,但AFHTTPClient
已替换为AFHTTPRequestOperationManager
和AFHTTPSessionManager
。
另请查看example app for 2.0 - AFAppDotNetAPIClient
now子类AFHTTPSessionManager
。
答案 1 :(得分:4)
在AFNetworking 3.0中,您需要使用AFHTTPSessionManager而不是AFHTTPRequestOperationManager,因为AFHTTPRequestOperationManager已被删除