AFNetworking is a delightful networking library for iOS and Mac OS X. It's built on top of the Foundation URL Loading System, extending the powerful high-level networking abstractions built into Cocoa. It has a modular(模块化的) architecture (架构)with well-designed, feature-rich APIs that are a joy to use.
Perhaps the most important feature of all, however, is the amazing community of developers who use and contribute to AFNetworking every day. AFNetworking powers some of the most popular and critically-acclaimed apps on the iPhone, iPad, and Mac.
Choose AFNetworking for your next project, or migrate(移居) over your existing projects—you'll be happy you did!
How To Get Started
Download AFNetworking and try out the included Mac and iPhone example apps
Read the "Getting Started" guide(指南), FAQ(常见问题), or other articles on the Wiki
Check out the documentation(API文档) for a comprehensive look(概况性地了解) at all of the APIs available in AFNetworking
Read the AFNetworking 3.0 Migration Guide for an overview of the architectural changes from 2.0.
Communication(沟通交流)
If you need help, use Stack Overflow. (Tag 'afnetworking')
If you'd like to ask a general question(一般性问题), use Stack Overflow.
If you found a bug, and can provide steps to reliably reproduce it, open an issue.
If you have a feature request(功能请求), open an issue.
If you want to contribute, submit a pull request.
Installation with CocoaPods
CocoaPods is a dependency manager for Objective-C, which automates(自动地) and simplifies the process of using 3rd-party libraries like AFNetworking in your projects. See the "Getting Started" guide for more information. You can install it with the following command:
$ gem install cocoapods
Podfile
To integrate AFNetworking into your Xcode project using CocoaPods, specify it in your Podfile:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
target 'TargetName' do
pod 'AFNetworking', '~> 3.0'
end
Then, run the following command:
$ pod install
Installation with Carthage (略)
Architecture(架构!!!)
NSURLSession(会话部分)
AFURLSessionManager
AFHTTPSessionManager
Serialization(序列化)
AFURLRequestSerialization
AFHTTPRequestSerializer(HTTP请求序列化)
AFJSONRequestSerializer(jons请求序列化)
AFPropertyListRequestSerializer(属性列表请求序列化)
AFURLResponseSerialization(响应序列化)
AFHTTPResponseSerializer
AFJSONResponseSerializer
AFXMLParserResponseSerializer
AFXMLDocumentResponseSerializer (Mac OS X)
AFPropertyListResponseSerializer
AFImageResponseSerializer
AFCompoundResponseSerializer
Additional Functionality(其他功能)
AFSecurityPolicy(安全策略)
AFNetworkReachabilityManager(网络状态)
Usage(用法)
AFURLSessionManager
AFURLSessionManager creates and manages(创建并管理) an NSURLSession object(会话对象) based on a specified NSURLSessionConfiguration object, which conforms to NSURLSessionTaskDelegate,NSURLSessionDataDelegate,NSURLSessionDownloadDelegate, andNSURLSessionDelegate.(四个协议)
Creating a Download Task(创建一个下载任务)
Creating an Upload Task(创建一个上传任务)
Creating an Upload Task for a Multi-Part Request, with Progress
Creating a Data Task
Request Serialization(请求序列化)
Request serializers create requests from URL strings, encoding parameters as either a query string or HTTP body.
Query String Parameter Encoding
URL Form Parameter Encoding
JSON Parameter Encoding
Network Reachability Manager(网络状态管理器)
AFNetworkReachabilityManager monitors(监视器) the reachability of domains, and addresses for both WWAN and WiFi network interfaces.
Do not use Reachability to determine if the original request should be sent.
You should try to send it.
You can use Reachability to determine when a request should be automatically retried.
Although it may still fail, a Reachability notification that the connectivity(连接) is available is a good time to retry something.
Network reachability is a useful tool(使用工具) for determining(查明,确定) why a request might have failed.
After a network request has failed, telling the user they're offline is better than giving them a more technical but accurate error, such as "request timed out."(请求超时)
Shared Network Reachability
Security Policy(安全策略)
AFSecurityPolicy evaluates server trust against pinned X.509 certificates and public keys over secure connections.(公钥)
Adding pinned SSL(Secure Sockets Layer 安全套接层,及其继任者传输层安全(Transport Layer Security,TLS)是为网络通信提供安全及数据完整性的一种安全协议) certificates to your app helps prevent man-in-the-middle attacks and other vulnerabilities(易受攻击). Applications dealing with sensitive customer data or financial information are strongly encouraged to route all communication over an HTTPS connection with SSL pinning configured and enabled.
网友评论