使用未声明的标识符AFHTTPClient

 宋雨甄_938 发布于 2023-01-30 19:08

嗨,我正在尝试编译以下代码,但收到错误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 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'

James Frost.. 10

你包括AFNetworking 2.0,但AFHTTPClient在2.0中不存在 - 这是一个1.0功能.检查迁移指南,但AFHTTPClient已被AFHTTPRequestOperationManager和替换AFHTTPSessionManager.

另请参阅2.0 的示例应用程序 - AFAppDotNetAPIClient现在是子类AFHTTPSessionManager.

1 个回答
  • 你包括AFNetworking 2.0,但AFHTTPClient在2.0中不存在 - 这是一个1.0功能.检查迁移指南,但AFHTTPClient已被AFHTTPRequestOperationManager和替换AFHTTPSessionManager.

    另请参阅2.0 的示例应用程序 - AFAppDotNetAPIClient现在是子类AFHTTPSessionManager.

    2023-01-30 19:09 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有