Use of undeclared identifier AFHTTPClient
Asked Answered
H

2

9

Hi I am trying to compile following code but getting error 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];

I am useing CocoaPods and here is my pod file:

platform :ios, '7'
pod 'AFNetworking', '~> 2.0'
pod 'AFNetworking/NSURLSession', '~> 2.0'
Hann answered 28/1, 2014 at 14:32 Comment(2)
What are your #imports?Flacon
AfNetworking 2.0 remove AFHTTPClient see #19504250Bard
V
10

You're including AFNetworking 2.0, but AFHTTPClient doesn't exist in 2.0 - it was a 1.0 feature. Check the migration guide but AFHTTPClient has been replaced by AFHTTPRequestOperationManager and AFHTTPSessionManager.

Also take a look at the example app for 2.0 - AFAppDotNetAPIClient now subclasses AFHTTPSessionManager.

Veliger answered 28/1, 2014 at 14:36 Comment(0)
L
4

In AFNetworking 3.0 you need to use AFHTTPSessionManager instead of AFHTTPRequestOperationManager, because AFHTTPRequestOperationManager was removed

Lavettelavigne answered 17/12, 2015 at 9:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.