gpt4 book ai didi

ios - 使用未声明的标识符 AFHTTPClient

转载 作者:技术小花猫 更新时间:2023-10-29 11:16:55 24 4
gpt4 key购买 nike

您好,我正在尝试编译以下代码,但出现错误 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'

最佳答案

您包括 AFNetworking 2.0,但 AFHTTPClient 在 2.0 中不存在 - 它是 1.0 的功能。检查migration guideAFHTTPClient 已被 AFHTTPRequestOperationManagerAFHTTPSessionManager 取代。

另请查看 example app对于 2.0 - AFAppDotNetAPIClient 现在是 AFHTTPSessionManager 的子类。

关于ios - 使用未声明的标识符 AFHTTPClient,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21408402/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com