AFHTTPClient.m不再在AFNetworking中? [英] AFHTTPClient.m no longer in AFNetworking?

查看:185
本文介绍了AFHTTPClient.m不再在AFNetworking中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注使用AFNetworking的教程( http://bit.ly/1dbLaPh )。它说要创建一个从AFHTTPClient子类化的新类。此选项不会显示在字段的子类字段中。我检查了AFNetworking文件夹,并且没有AFHTTPClient.m实现文件。此文件是否已重命名为其他内容?

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?

谢谢,

推荐答案

在AFNetworking 2.0中,AFHTTPClient已被AFHTTPRequestOperationManager / AFHTTPSessionManager取代。我建议你参考示例 .Git克隆并在XCode中打开。它应该对你有帮助。这是最新的例子。

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.

如果你想使用AFHTTPClient即1.x代码。这是 git链接到分支。该pod的规格将是

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'

在2.0 AFNetworking中,您可以像这样创建一个单独的客户端。 / p>

interface



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

@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

这篇关于AFHTTPClient.m不再在AFNetworking中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆