- 浏览: 581934 次
- 性别:
- 来自: 广州
文章分类
最新评论
-
JYY282:
[i][/i]
Ecshop与Shopex的比较 -
qq247890212:
我也遇见这问题了,真诡异。重新下载个猫换了就好了。 太浪费时间 ...
诡异:ClassNotFoundException: org.springframework.web.filter.CharacterEncoding
AFNetworking on github: https://github.com/AFNetworking/AFNetworking
AFNetworking is a delightful networking library for iOS and Mac OS X. It's built on top of NSURLConnection, NSOperation, and other familiar Foundation technologies. It has a modular architecture with well-designed, feature-rich APIs that are a joy to use. For example, here's how easy it is to get JSON from a URL:
NSURL *url = [NSURL URLWithString:@"http://api.twitter.com/1/statuses/public_timeline.json"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
NSLog(@"Public Timeline: %@", JSON);
} failure:nil];
[operation start];
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 in the wiki
- Check out the complete documentation for a comprehensive look at the APIs available in AFNetworking
- Watch the NSScreencast episode about AFNetworking for a quick introduction to how to use it in your application
- Questions? Stack Overflow is the best place to find answers
Overview
AFNetworking is architected to be as small and modular as possible, in order to make it simple to use and extend.
AFURLConnectionOperation | An NSOperation that implements the NSURLConnection delegate methods. |
AFHTTPRequestOperation | A subclass of AFURLConnectionOperation for requests using the HTTP or HTTPS protocols. It encapsulates the concept of acceptable status codes and content types, which determine the success or failure of a request. |
AFJSONRequestOperation | A subclass of AFHTTPRequestOperation for downloading and working with JSON response data. |
AFXMLRequestOperation | A subclass of AFHTTPRequestOperation for downloading and working with XML response data. |
AFPropertyListRequestOperation | A subclass of AFHTTPRequestOperation for downloading and deserializing objects withproperty list response data. |
AFHTTPClient | Captures the common patterns of communicating with an web application over HTTP, including:
|
AFImageRequestOperation | A subclass of AFHTTPRequestOperation for downloading and processing images. |
UIImageView+AFNetworking | Adds methods to UIImageView for loading remote images asynchronously from a URL. |
Example Usage
XML Request
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://api.flickr.com/services/rest/?method=flickr.groups.browse&api_key=b6300e17ad3c506e706cb0072175d047&cat_id=34427469792%40N01&format=rest"]];
AFXMLRequestOperation *operation = [AFXMLRequestOperation XMLParserRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, NSXMLParser *XMLParser) {
XMLParser.delegate = self;
[XMLParser parse];
} failure:nil];
[operation start];
Image Request
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 100.0f, 100.0f)];
[imageView setImageWithURL:[NSURL URLWithString:@"http://i.imgur.com/r4uwx.jpg"] placeholderImage:[UIImage imageNamed:@"placeholder-avatar"]];
API Client Request
// AFGowallaAPIClient is a subclass of AFHTTPClient, which defines the base URL and default HTTP headers for NSURLRequests it creates
[[AFGowallaAPIClient sharedClient] getPath:@"/spots/9223" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Name: %@", [responseObject valueForKeyPath:@"name"]);
NSLog(@"Address: %@", [responseObject valueForKeyPath:@"address.street_address"]);
} failure:nil];
File Upload with Progress Callback
NSURL *url = [NSURL URLWithString:@"http://api-base-url.com"];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
NSData *imageData = UIImageJPEGRepresentation([UIImage imageNamed:@"avatar.jpg"], 0.5);
NSMutableURLRequest *request = [httpClient multipartFormRequestWithMethod:@"POST" path:@"/upload" parameters:nil constructingBodyWithBlock: ^(id <AFMultipartFormData>formData) {
[formData appendPartWithFileData:imageData name:@"avatar" fileName:@"avatar.jpg" mimeType:@"image/jpeg"];
}];
AFHTTPRequestOperation *operation = [[[AFHTTPRequestOperation alloc] initWithRequest:request] autorelease];
[operation setUploadProgressBlock:^(NSInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {
NSLog(@"Sent %lld of %lld bytes", totalBytesWritten, totalBytesExpectedToWrite);
}];
[operation start];
Streaming Request
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://localhost:8080/encode"]];
AFHTTPRequestOperation *operation = [[[AFHTTPRequestOperation alloc] initWithRequest:request] autorelease];
operation.inputStream = [NSInputStream inputStreamWithFileAtPath:[[NSBundle mainBundle] pathForResource:@"large-image" ofType:@"tiff"]];
operation.outputStream = [NSOutputStream outputStreamToMemory];
[operation start];
Requirements
AFNetworking requires either iOS 4.0 and above, or Mac OS 10.6 (64-bit with modern Cocoa runtime) and above.
AFNetworking uses NSJSONSerialization
if it is available. If your app targets a platform where this class is not available you can include one of the following JSON libraries to your project for AFNetworking to automatically detect and use.
ARC Support
AFNetworking will transition its codebase to ARC in a future release.
If you are including AFNetworking in a project that uses Automatic Reference Counting (ARC) enabled, you will need to set the-fno-objc-arc
compiler flag on all of the AFNetworking source files. To do this in Xcode, go to your active target and select the "Build Phases" tab. Now select all AFNetworking source files, press Enter, insert -fno-objc-arc
and then "Done" to disable ARC for AFNetworking.
发表评论
-
Objective-C 与 C++ 的异同
2013-04-02 12:03 1401http://www.cnblogs.com/y041039 ... -
Cocos2D-X是全球知名的开源跨平台手机游戏引擎
2013-01-22 10:05 2757http://www.oschina.net/p/cocos ... -
iOS Keyboard 键盘高度变化 自适应
2013-01-15 15:43 3252[[NSNotificationCenter default ... -
iOS使用自定义字体
2012-11-27 12:11 12145From: http://blog.csdn.net/csy1 ... -
4 款类似 Facebook/Path 切换效果的 iOS 组件
2012-11-27 12:03 2199From: http://blog.csdn.net/lia ... -
Path 2.0的UI界面设计详细介绍
2012-11-27 11:56 1469如Path的创始人Dave Morin ... -
史上最全的App Store邮箱列表
2012-11-27 11:51 1272From: http://roybaby.blog.51cto ... -
iOS从info.plist 获取项目的名称及版本号
2012-11-16 10:54 1675From: http://blog.sina.com.cn/s ... -
MapKit annotation drag and drop with callout info update
2012-10-13 10:38 2409http://hollowout.blogspot ... -
NSArray 或NSDictionary 调用writeToFile方法失败原因
2012-08-31 10:03 4489NSArray 或NSDictionary 调用writeTo ... -
如何让IOS应用从容地崩溃
2012-08-30 15:25 1621From: http://www.cocoachina.com ... -
iOS中判断设备系统版本
2012-08-29 17:17 31716在iOS开发中,经常要考虑系统的向下兼容,如果使用 ... -
iOS 汉字转拼音
2012-08-21 16:42 1470From: http://www.cnblogs.com/v2 ... -
iOS模拟器截图工具
2012-08-17 16:35 1663From: http://magicalboy.com/ios ... -
XCode下的iOS单元测试
2012-08-10 17:47 1171From: http://mobile.51cto.com/ ... -
Wrapping Conventions
2012-08-01 15:54 825Wrapping Conventions ... -
Core Animation如何使显式动画结束时的值直接作用Layer
2012-08-01 14:51 3798(1)使用隐式动画会直接改变layer的属性值,如: ima ... -
How To Debug Memory Leaks with XCode and Instruments Tutoria
2012-07-31 16:30 1058From: http://www.raywenderlich. ... -
Using Properties in Objective-C Tutorial
2012-07-31 16:27 931From: http://www.raywenderlich. ... -
appstore 收款: 如何绑定收款的银行卡?
2012-07-27 09:07 9439From: http://www.oschina.net/qu ...
相关推荐
在AFNetworking 4.0+版本中,开发者进行了更多的封装,使得功能更加完善,同时也提升了性能和用户体验。本文将深入探讨AFNetworking 4.0+封装的几个关键知识点,包括请求缓存、离线下载、显示缓存大小、删除缓存以及...
AFNetworking是中国iOS开发者广泛使用的网络请求库,它是由Alamofire团队为Objective-C开发者设计的。这个库使得处理网络请求变得更加简单和高效。在“AFNetWorking直接引入工程”这个主题下,我们将深入探讨如何将...
AFNetworking是iOS开发中常用的网络请求库,它基于Objective-C编写,为iOS和macOS平台提供了强大的网络请求处理能力。本篇文章将详细讲解AFNetworking的常用封装和如何进行请求操作,帮助开发者更好地理解和使用这个...
AFNetworking是iOS和macOS平台上的一款强大的开源网络库,由Alamofire Software Foundation维护。它以其简洁、易用和高效而备受开发者喜爱,主要用于处理HTTP网络请求,包括上传和下载任务。在iOS应用开发中,...
这个压缩包“ios-AFNetworking的下载、请求、上传.zip”显然包含了关于如何使用AFNetworking进行网络下载、请求以及上传的示例代码,虽然上传部分可能存在问题。接下来,我们将深入探讨AFNetworking的核心功能和使用...
AFNetWorking是iOS和macOS平台上广泛使用的网络请求库,由Alamofire Software Foundation维护。这个库是Objective-C编写的,为开发者提供了强大的HTTP网络请求功能,简化了网络编程的工作。其中,`...
AFNetworking发送post请求出现999错误解决方案 从给定的文件信息中,我们可以提炼出以下知识点: 1. AFNetworking是一个基于HTTP/HTTPS的网络请求框架,用于简化iOS和OS X应用程序中的网络交互。 在AFNetworking...
**AFNetworking 2.5 使用详解** AFNetworking 是一个强大的 iOS 和 macOS 开发中的网络库,它基于 NSURLConnection、NSURLSession 和其他系统框架构建,提供了一套简洁易用的接口来处理 HTTP 请求和响应。在 ...
在“超强的AFNetWorking封装框架”中,我们将会探讨如何利用AFNetworking进行POST和GET请求,以及如何对其进行优化封装,以实现更简单、更方便的网络操作。 1. **AFNetworking基础** - AFNetworking基于苹果的...
**AFNetworking 3.0.3:iOS网络编程的强大工具** AFNetworking,作为一个广受欢迎的开源库,是iOS开发中的重要组件,特别是在处理网络请求和数据传输方面。这个版本3.0.3提供了稳定和高效的解决方案,使得开发者...
**AFNetWorking——iOS平台的网络请求库** 在iOS应用开发中,网络请求是不可或缺的一部分,用于获取服务器上的数据或提交用户操作。AFNetWorking,作为iOS平台上最流行且功能强大的网络请求库,极大地简化了网络...
在iOS开发中,AFNetworking能够极大地提升开发效率,因为它简化了网络数据的获取、上传和下载过程。 AFNetworking的核心功能包括: 1. **GET与POST请求**:AFNetworking提供了简单的方法来发起GET和POST请求。GET...
在iOS开发中,网络请求是应用与服务器交互的基础,而AFNetworking是Objective-C及Swift中最常用的网络库之一。本文将深入探讨如何基于AFNetworking进行接口封装,以提高代码的可复用性和可维护性。 首先,...
在iOS开发中,网络请求是不可或缺的一部分,而AFNetworking作为苹果平台最受欢迎的网络库,极大地简化了网络操作。本教程将深入讲解如何使用AFNetworking 3.0实现图片上传功能,这对于任何涉及到用户交互和多媒体...
在标题"AFNetworking.3.0-兼容ipv6.zip"中提到的“3.0”指的是AFNetworking的版本号,这表明我们关注的是该库的一个特定更新,即3.0版。这个版本对IPv6的支持是其重要的特性之一。描述中提到的“已实现兼容ipv6网络...
AFNetWorking库是iOS平台上非常流行的网络请求库,由Alamofire Software Foundation维护。这个库使得处理网络请求,包括数据加载、文件下载以及图片加载等任务变得简单高效。在本Demo中,我们将专注于如何使用...