- 浏览: 569444 次
- 性别:
- 来自: 广州
文章分类
最新评论
-
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 1355http://www.cnblogs.com/y041039 ... -
Cocos2D-X是全球知名的开源跨平台手机游戏引擎
2013-01-22 10:05 2707http://www.oschina.net/p/cocos ... -
iOS Keyboard 键盘高度变化 自适应
2013-01-15 15:43 3215[[NSNotificationCenter default ... -
iOS使用自定义字体
2012-11-27 12:11 12073From: http://blog.csdn.net/csy1 ... -
4 款类似 Facebook/Path 切换效果的 iOS 组件
2012-11-27 12:03 2085From: http://blog.csdn.net/lia ... -
Path 2.0的UI界面设计详细介绍
2012-11-27 11:56 1423如Path的创始人Dave Morin ... -
史上最全的App Store邮箱列表
2012-11-27 11:51 1215From: http://roybaby.blog.51cto ... -
iOS从info.plist 获取项目的名称及版本号
2012-11-16 10:54 1571From: http://blog.sina.com.cn/s ... -
MapKit annotation drag and drop with callout info update
2012-10-13 10:38 2360http://hollowout.blogspot ... -
NSArray 或NSDictionary 调用writeToFile方法失败原因
2012-08-31 10:03 4421NSArray 或NSDictionary 调用writeTo ... -
如何让IOS应用从容地崩溃
2012-08-30 15:25 1569From: http://www.cocoachina.com ... -
iOS中判断设备系统版本
2012-08-29 17:17 31667在iOS开发中,经常要考虑系统的向下兼容,如果使用 ... -
iOS 汉字转拼音
2012-08-21 16:42 1420From: http://www.cnblogs.com/v2 ... -
iOS模拟器截图工具
2012-08-17 16:35 1579From: http://magicalboy.com/ios ... -
XCode下的iOS单元测试
2012-08-10 17:47 1118From: http://mobile.51cto.com/ ... -
Wrapping Conventions
2012-08-01 15:54 778Wrapping Conventions ... -
Core Animation如何使显式动画结束时的值直接作用Layer
2012-08-01 14:51 3745(1)使用隐式动画会直接改变layer的属性值,如: ima ... -
How To Debug Memory Leaks with XCode and Instruments Tutoria
2012-07-31 16:30 1016From: http://www.raywenderlich. ... -
Using Properties in Objective-C Tutorial
2012-07-31 16:27 877From: http://www.raywenderlich. ... -
appstore 收款: 如何绑定收款的银行卡?
2012-07-27 09:07 9367From: http://www.oschina.net/qu ...
相关推荐
AFNetWorking
完整的AFNetworking请求封装,大部分都有注释。进一步的靠近mvc模式。如果你第一次尝试封装AFNetworking就不要错过。
经过自己调过的AFNetWorking,可以直接引入工程中
AFNetWorking工具库 AFJSONRequestOperation
iOS开发网络数据之AFNetworking使用,没有积分的可以在对应文章下评论留下邮箱; 文章地址:http://blog.csdn.net/daiyelang/article/details/38421341
基于AFNetworking3.0以上版本所写的网络封装,将在开发中常用的API封装起来,在开发中就可以更简单地使用。 由于AFN2.0与AFN3.0的版本,有很大的变化,到现在才有时间基于AFN3.0写一个。代码不代表都合大家使用,...
上传 下载 AFnetworking 帮助你实现网络请求 具体学习请上官网
1.基于AFNetworking3.1.0封装的GET,POST请求.支持简单的图片上传和其他资源下载. 2.代码中有常用分类,为了避免分类方法重命名都已相应加上前缀. 3.代码中有常用宏定义. 4.分类和宏定义中有很多强大及方便的快捷...
基于AFNetworking的接口封装
最近很多人问一些基于AFNetworking3.0网络请求的封装,其实不用真的不用封装,唯一需要封装的地方就是客户端做缓存,统一把所有请求做了缓存接口。缓存用的是YYCache。基于AFNetworking的demo
新版AFNetworking的使用方法和例子
Network, 根据AFNetworking3.0框架封装的,实现了GET、POST、PUT、DELETE、上传文件、下载文件、文件上传下载进度条等功能,同时支持IPv6。 为什么使用它? 1. 简单快捷,只需要一句代码即可请求网络和文件处理 2....
1.基于AFNetworking3.1.0封装的GET,POST请求.支持简单的图片上传和其他资源下载. 2.代码中有常用分类,为了避免分类方法重命名都已相应加上前缀. 3.代码中有常用宏定义. 4.分类和宏定义中有很多强大及方便的快捷...
AFNetworking4.0+封装GET / POST等 1.请求缓存 2.离线下载 3.显示缓存大小 4.删除缓存 5.取消当前请求
AFNetworking2.5使用,没有积分的可以在对应文章下评论留下邮箱; 文章地址:http://blog.csdn.net/daiyelang/article/details/38434023
超强的网络请求框架AFNetWorking,POST、get请求,简单方便
简单的实现了AFNetworking 3.0的图片上传功能
AFNetworking官方文档 ios pdf资源 官方文档加中文注释
AFNetworking 官方文档+翻译 感谢大神 来自无限互联