资料来源 : http://github.ibireme.com/github/list/ioshtml
GitHub : 连接地址ios
简介 :git
A delightful iOS and OS X networking framework.github
推荐参考 : web
http://afnetworking.comjson
http://www.aiuxian.com/article/p-1537192.htmlxcode
连接地址1、 文件目录
连接地址1. AFNetworking 目录内容

连接地址2. UIKit+AFNetworking 目录内容

连接地址3. 关联关系(AFNetworking)

连接地址2、 详细介绍
连接地址1. AFNetworking
这是 AFNetworking 的主要部分,包括 6 个功能部分共 9 个类。安全
连接地址1)AFNetworking.h
- #import <Foundation/Foundation.h>
- #import <Availability.h>
-
- #ifndef _AFNETWORKING_
- #define _AFNETWORKING_
-
- #import "AFURLRequestSerialization.h"
- #import "AFURLResponseSerialization.h"
- #import "AFSecurityPolicy.h"
- #import "AFNetworkReachabilityManager.h"
-
- #import "AFURLConnectionOperation.h"
- #import "AFHTTPRequestOperation.h"
- #import "AFHTTPRequestOperationManager.h"
-
- #if ( ( defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 1090) || \
- ( defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000 ) )
- #import "AFURLSessionManager.h"
- #import "AFHTTPSessionManager.h"
- #endif
-
- #endif /* _AFNETWORKING_ */
这是 AFNetworking 的公共头文件,在使用 AFNetworking 库时可直接在 Prefix.pch 文件中引入,或者在工程的网络管理模块相关文件中引入。 网络
连接地址2)AFSecurityPolicy.h
- @interface AFSecurityPolicy : NSObject
-
- @property (nonatomic, assign) AFSSLPinningMode SSLPinningMode;
-
- @property (nonatomic, assign) BOOL validatesCertificateChain;
-
- @property (nonatomic, strong) NSArray *pinnedCertificates;
-
- @property (nonatomic, assign) BOOL allowInvalidCertificates;
-
- @property (nonatomic, assign) BOOL validatesDomainName;
这个类主要是为网络请求添加 SSL 安全验证, SSL 安全验证类型有以下三种,默认是 AFSSLPinningModeNone 类型,另外经过 SSL 证书和密钥能够增长请求的安全性,避免请求被劫持和攻击。session
- typedef NS_ENUM(NSUInteger, AFSSLPinningMode) {
- AFSSLPinningModeNone,
- AFSSLPinningModePublicKey,
- AFSSLPinningModeCertificate,
- };
关于 SSL 和数字证书相关可参考这里(SSL)和这里(数字证书)。
连接地址3)AFNetworkReachabilityManager.h
- @interface AFNetworkReachabilityManager : NSObject
-
- @property (readonly, nonatomic, assign) AFNetworkReachabilityStatus networkReachabilityStatus;
-
- @property (readonly, nonatomic, assign, getter = isReachable) BOOL reachable;
-
- @property (readonly, nonatomic, assign, getter = isReachableViaWWAN) BOOL reachableViaWWAN;
-
- @property (readonly, nonatomic, assign, getter = isReachableViaWiFi) BOOL reachableViaWiFi;
这个类和苹果官方提供的 Reachability 类功能相似,可是功能更增强大,不只增长了更多的公共属性,也增长了状态变动闭包(block)操做,还增长了通知标志串,用过 Reachability 应该可以很快理解并爱上这个类。
连接地址4)AFURLConnectionOperation.h
- @interface AFURLConnectionOperation : NSOperation <NSURLConnectionDelegate, NSURLConnectionDataDelegate, NSCoding, NSCopying>
-
-
- @property (nonatomic, strong) NSSet *runLoopModes;
-
-
- @property (readonly, nonatomic, strong) NSURLRequest *request;
-
- @property (readonly, nonatomic, strong) NSURLResponse *response;
-
- @property (readonly, nonatomic, strong) NSError *error;
-
-
- @property (readonly, nonatomic, strong) NSData *responseData;
-
- @property (readonly, nonatomic, copy) NSString *responseString;
-
- @property (readonly, nonatomic, assign) NSStringEncoding responseStringEncoding;
-
-
- @property (nonatomic, assign) BOOL shouldUseCredentialStorage;
-
- @property (nonatomic, strong) NSURLCredential *credential;
-
-
- @property (nonatomic, strong) AFSecurityPolicy *securityPolicy;
-
-
- @property (nonatomic, strong) NSInputStream *inputStream;
-
- @property (nonatomic, strong) NSOutputStream *outputStream;
-
-
- @property (nonatomic, strong) dispatch_queue_t completionQueue;
-
- @property (nonatomic, strong) dispatch_group_t completionGroup;
-
-
- @property (nonatomic, strong) NSDictionary *userInfo;
这是一个 NSOperation 子类,它实现了 NSURLConnection 的所有代理方法,所执行的是单个网络请求的操做。
连接地址5)AFHTTPRequestOperation.h
- @interface AFHTTPRequestOperation : AFURLConnectionOperation
-
-
- @property (readonly, nonatomic, strong) NSHTTPURLResponse *response;
-
- @property (nonatomic, strong) AFHTTPResponseSerializer <AFURLResponseSerialization> * responseSerializer;
-
- @property (readonly, nonatomic, strong) id responseObject;
这是 AFURLConnectionOperation 的子类,主要针对 HTTP 和 HTTPS 类型的请求,这也是最经常使用的请求操做。
连接地址6)AFHTTPRequestOperationManager.h
- @interface AFHTTPRequestOperationManager : NSObject <NSCoding, NSCopying>
-
- @property (readonly, nonatomic, strong) NSURL *baseURL;
-
- @property (nonatomic, strong) AFHTTPRequestSerializer <AFURLRequestSerialization> * requestSerializer;
-
- @property (nonatomic, strong) AFHTTPResponseSerializer <AFURLResponseSerialization> * responseSerializer;
-
- @property (nonatomic, strong) NSOperationQueue *operationQueue;
-
-
- @property (nonatomic, assign) BOOL shouldUseCredentialStorage;
-
- @property (nonatomic, strong) NSURLCredential *credential;
-
-
- @property (nonatomic, strong) AFSecurityPolicy *securityPolicy;
-
-
- @property (readwrite, nonatomic, strong) AFNetworkReachabilityManager *reachabilityManager;
这是 AFHTTPRequestOperation 的一个管理类,细化了不一样类型的请求操做( GET、HEAD、POST、PUT、PATCH、DELETE ),经过这个管理类建立的网络请求操做都会被加入到 operationQueue 中执行。
连接地址7)AFURLSessionManager.h
- @interface AFURLSessionManager : NSObject <NSURLSessionDelegate, NSURLSessionTaskDelegate, NSURLSessionDataDelegate, NSURLSessionDownloadDelegate, NSCoding, NSCopying>
-
- @property (readonly, nonatomic, strong) NSURLSession *session;
-
- @property (readonly, nonatomic, strong) NSOperationQueue *operationQueue;
-
- @property (nonatomic, strong) id <AFURLResponseSerialization> responseSerializer;
-
-
- @property (nonatomic, strong) AFSecurityPolicy *securityPolicy;
-
-
- @property (readwrite, nonatomic, strong) AFNetworkReachabilityManager *reachabilityManager;
-
-
- @property (readonly, nonatomic, strong) NSArray *tasks;
-
- @property (readonly, nonatomic, strong) NSArray *dataTasks;
-
- @property (readonly, nonatomic, strong) NSArray *uploadTasks;
-
- @property (readonly, nonatomic, strong) NSArray *downloadTasks;
-
-
- @property (nonatomic, strong) dispatch_queue_t completionQueue;
-
- @property (nonatomic, strong) dispatch_group_t completionGroup;
这是 AFNetworking 实现的 NSURLSession 的一个管理类,在这个类里面已经实现了所有相关的 NSURLSession 代理方法,NSURLSession 是 iOS7 新增长的用于网络请求相关的任务类,具体可参考 这里(苹果官方文档) 、 这里(相关博客一) 和 这里(相关博客二) 。
连接地址8)AFHTTPSessionManager.h
- @interface AFHTTPSessionManager : AFURLSessionManager <NSCoding, NSCopying>
-
- @property (readonly, nonatomic, strong) NSURL *baseURL;
-
- @property (nonatomic, strong) AFHTTPRequestSerializer <AFURLRequestSerialization> * requestSerializer;
-
- @property (nonatomic, strong) AFHTTPResponseSerializer <AFURLResponseSerialization> * responseSerializer;
这是 AFURLSessionManager 的一个管理类,针对 HTTP 细化了不一样类型的请求操做( GET、HEAD、POST、PUT、PATCH、DELETE ),由于 NSURLSession 是 iOS7 新增长的用于网络请求相关的任务类,因此仅针对 iOS7 系统时可考虑优先使用这个管理类替代 AFHTTPRequestOperationManager ,若是须要考虑向前兼容,仍是须要使用 AFHTTPRequestOperationManager 。
连接地址9)AFURLRequestSerialization.h
这个文件主要定义了一些用于网络请求的协议和类,其中包括了请求格式、请求参数以及相关请求设置的方法。
连接地址10)AFURLResponseSerialization.h
这个文件主要定义了一些网络返回数据格式以及解析的协议和类,包括JSON、XML、Image等格式的返回数据获取和格式解析等。
连接地址2. UIKit+AFNetworking
这是 AFNetworking 针对 UIKit 部分系统控件作的类别扩展,包括 1 个管理类定义和 8 个类别扩展。
连接地址1)UIKit+AFNetworking.h
- #import <UIKit/UIKit.h>
-
- #ifndef _UIKIT_AFNETWORKING_
- #define _UIKIT_AFNETWORKING_
-
- #import "AFNetworkActivityIndicatorManager.h"
-
- #import "UIActivityIndicatorView+AFNetworking.h"
- #import "UIAlertView+AFNetworking.h"
- #import "UIButton+AFNetworking.h"
- #import "UIImageView+AFNetworking.h"
- #import "UIKit+AFNetworking.h"
- #import "UIProgressView+AFNetworking.h"
- #import "UIWebView+AFNetworking.h"
- #endif /* _UIKIT_AFNETWORKING_ */
这是 UIKit+AFNetworking 的公共头文件,若是须要使用 AFNetworking 的 UIKit 扩展时可直接在 Prefix.pch 文件中引入,或者在工程的相关文件中引入。
连接地址2)AFNetworkActivityIndicatorManager.h
- @interface AFNetworkActivityIndicatorManager : NSObject
-
- @property (nonatomic, assign, getter = isEnabled) BOOL enabled;
-
- @property (readonly, nonatomic, assign) BOOL isNetworkActivityIndicatorVisible;
这个类主要是为了自动显示和隐藏请求时的状态提示,若是你确实须要它的话用这个类仍是很方便的,使用方法也很简单。只要在 AppDelegate application:didFinishLaunchingWithOptions: 方法中添加一句
- [[AFNetworkActivityIndicatorManager sharedManager] setEnabled:YES];
就能够了,以后在使用 AFNetworking 发起请求和终止请求时都会自动显示和隐藏状态提示。
连接地址3)UIActivityIndicatorView+AFNetworking.h
- #import <Foundation/Foundation.h>
-
- #import <Availability.h>
-
- #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
-
- #import <UIKit/UIKit.h>
-
- @class AFURLConnectionOperation;
-
- @interface UIActivityIndicatorView (AFNetworking)
-
-
- #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 70000
- - (void)setAnimatingWithStateOfTask:(NSURLSessionTask *)task;
- #endif
-
-
- - (void)setAnimatingWithStateOfOperation:(AFURLConnectionOperation *)operation;
-
- @end
这个类别为网络请求的状态显示增长了两个方法,经过这两个方法能够根据当前任务的状态或操做的状态决定网络请求状态的显示与隐藏。
连接地址4)UIAlertView+AFNetworking.h
和上面的类别相似,不过这个类别主要是为 UIAlertView 增长了几个方法,当相关的网络任务和请求操做发生错误时,会弹出一个 UIAlertView ,虽然 iOS7 的 UIAlertView 看上去温柔不少,很我我的仍是很讨厌这个粗暴的弹出提示,我一样不喜欢转圈圈的等待提示。
连接地址5)UIButton+AFNetworking.h
这个类别主要是为 UIButton 增长了异步获取网络图片的类别方法,用过相似 EGOImageView 的应该很容易理解。
连接地址6)UIImageView+AFNetworking.h
说曹操曹操到,这个就是 EGOImageView 的 AFNetworking 版。
连接地址7)UIProgressView+AFNetworking.h
同 UIActivityIndicatorView+AFNetworking ,只是这个类别是针对 UIProgressView 的。
连接地址8)UIRefreshControl+AFNetworking.h
同 UIActivityIndicatorView+AFNetworking ,只是这个类别是针对 UIRefreshControl 的。UIRefreshControl 是 iOS7 新增长的下拉刷新显示控件,经过这个类别能够根据网络的行为和请求结果决定 UIRefreshControl 的显示状态。
连接地址9)UIWebView+AFNetworking.h
为 UIWebView 的载入请求增长了几个类别方法,便于决定请求成功失败如何显示,以及请求过程当中等待状态的显示等。
连接地址3、 一点总结
粗略的浏览完 AFNetworking 的源代码以后深入的感觉了一下那么一句话:“咱们不生产代码,咱们只是 Github 的搬运工!”。自省一下,继续努力!
http://www.aiuxian.com/article/p-1715579.html