使用未声明的标识符AFHTTPClient。

9

你好,我正在尝试编译以下代码,但是出现了错误使用未声明的标识符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'

你的“#import”是什么? - Wain
AfNetworking 2.0移除了AFHTTPClient请参考https://dev59.com/o3jZa4cB1Zd3GeqPbTrc - bugman79
2个回答

10
您正在使用AFNetworking 2.0,但是AFHTTPClient在2.0中不存在——它是1.0的功能。请查看迁移指南,但AFHTTPClient已被AFHTTPRequestOperationManagerAFHTTPSessionManager所取代。
此外,请查看2.0的示例应用程序 - AFAppDotNetAPIClient现在是AFHTTPSessionManager的子类。

4
在AFNetworking 3.0中,你需要使用AFHTTPSessionManager代替AFHTTPRequestOperationManager,因为AFHTTPRequestOperationManager已被移除。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接