AFNetworking 2.0 使用
2024-09-24 20:10:01
AFNetworking 下载地址:https://github.com/AFNetworking/AFNetworking/
AFNetworking 2.0 当Deployment Target 低于6.0时,AFURLConnectionOperation.h,AFURLSessionManager.h
@property (nonatomic, strong) dispatch_queue_t completionQueue;
由于sdk低于6.0时,dispatch_queue_t ARC没有托管,出现提示错误
Property with 'retain (or strong)' attribute must be of object type
修改为
#if OS_OBJECT_USE_OBJC
@property (nonatomic, strong) dispatch_queue_t completionQueue;
#else
@property (nonatomic, assign) dispatch_queue_t completionQueue;
#endif
使用示例:(不使用官方的自带的json和xml解析,返回NSData)
1.0兼容版
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
[manager GET:@"http://www.com" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) { } failure:^(AFHTTPRequestOperation *operation, NSError *error) { }];
2.0
AFHTTPSessionManager *httpSessionManager =[AFHTTPSessionManager manager];
httpSessionManager.responseSerializer = [AFHTTPResponseSerializer serializer];
NSURLSessionDataTask *task = [httpSessionManager GET:@"http://www.com" parameters:nil success:^(NSURLSessionDataTask *task, id responseObject)
{ } failure:^(NSURLSessionDataTask *task, NSError *error)
{ }];
IOS SDK 4.3以上兼容版,需要使用AFNetworking-0.10.x版本
AFHTTPClient *httpClient = [AFHTTPClient clientWithBaseURL:nil];
[httpClient getPath:@"http://www.com" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject)
{ } failure:^(AFHTTPRequestOperation *operation, NSError *error)
{ }];
最新文章
- solr_架构案例【京东站内搜索】(附程序源代码)
- 第11章 Linux服务管理
- ubuntu - 中文
- JavaMail邮件开发
- 『转载』C# winform 中dataGridView的重绘(进度条,虚线,单元格合并等)
- ubuntu下Tomcat7的安装和配置
- hibernate中session
- hOAuth2.0认证和授权原理
- c# String ,String[] 和 List<;String>;之间的转换
- 探索Windows命令行系列(1):导航目录
- HDU 1050(搬椅子 数学)
- babelrc
- Alpha(5/10)
- 【ZH奶酪】如何用Python实现编辑距离?
- iOS项目之“返回”手势操作相关
- nyoj 探寻宝藏
- C++ 常用函数方法
- (转载)ios的一些知识点
- Mac下使用Wine安装正则表达式工具RegexBuddy 4
- JAVA多线程提高七:Callable与Future的应用