AFHTTPClient.m no longer in AFNetworking?

13,688

In AFNetworking 2.0 the AFHTTPClient has been replaced by AFHTTPRequestOperationManager / AFHTTPSessionManager. I would suggest you to refer the example. Git clone and open in XCode. It should help you. That has the most updated example.

If you want to use AFHTTPClient i.e 1.x code. Here is the git link to the branch. The pod spec to that would be

pod 'AFNetworking',  '~> 1.3.3'

In 2.0 AFNetworking, you can create a singleton client like this.

interface

@interface AFAppDotNetAPIClient : AFHTTPSessionManager

+ (instancetype)sharedClient;

@end

Implementation

#import "AFAppDotNetAPIClient.h"

static NSString * const AFAppDotNetAPIBaseURLString = @"https://alpha-api.app.net/";

@implementation AFAppDotNetAPIClient

+ (instancetype)sharedClient {
    static AFAppDotNetAPIClient *_sharedClient = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _sharedClient = [[AFAppDotNetAPIClient alloc] initWithBaseURL:[NSURL URLWithString:AFAppDotNetAPIBaseURLString]];
        [_sharedClient setSecurityPolicy:[AFSecurityPolicy policyWithPinningMode:AFSSLPinningModePublicKey]];
    });

    return _sharedClient;
}

@end
Share:
13,688
Cybernetic
Author by

Cybernetic

Updated on July 29, 2022

Comments

  • Cybernetic
    Cybernetic almost 2 years

    I am following a tutorial (http://bit.ly/1dbLaPh) that uses AFNetworking. It says to make a new class that is subclassed from AFHTTPClient. This option does not appear in the SubClass Of" field. I checked the AFNetworking folder and there is no AFHTTPClient.m implementation file. Has this file been renamed to something else?

    thanks,

  • Pierre de LESPINAY
    Pierre de LESPINAY about 10 years
    Also checkout the Migration Guide