本文永久链接:http://www.cnblogs.com/qianLL/p/5342593.html

pod 'AFNetworking', '~>3.0.4'    <-------第三方

具体他的pod的过过程

http://www.cnblogs.com/qianLL/p/5331624.html

代码如下

#import "ViewController.h"
#import "AFNetworking.h"
@interface ViewController () @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
[self Upload];
// [self dataTask];
// [self MultiUpload];
// [self Serialization];
// [self PostMethod];
// [self Reacheab]; }
//下载
-(void)Download{
NSURLSessionConfiguration *configuration=[NSURLSessionConfiguration defaultSessionConfiguration]; AFURLSessionManager *manager=[[AFURLSessionManager alloc]initWithSessionConfiguration:configuration]; NSURL *URL=[NSURL URLWithString:@"example/download"];
NSURLRequest *request=[NSURLRequest requestWithURL:URL]; NSURLSessionDownloadTask *downloadTask=[manager downloadTaskWithRequest:request progress:nil destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {
NSURL *documentsDirectoryURL=[[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];
return [documentsDirectoryURL URLByAppendingPathComponent:[response suggestedFilename]];
} completionHandler:^(NSURLResponse * _Nonnull response, NSURL * _Nullable filePath, NSError * _Nullable error) {
NSLog(@"file downloaded to :%@",filePath);
}];
[downloadTask resume]; }
// 上传
-(void)Upload{
NSURLSessionConfiguration *configuration=[NSURLSessionConfiguration defaultSessionConfiguration]; AFURLSessionManager *manager=[[AFURLSessionManager alloc]initWithSessionConfiguration:configuration]; NSURL *url=[NSURL URLWithString:@"example/upload.php"]; NSURLRequest *request=[NSURLRequest requestWithURL:url]; NSURL *filePath=[NSURL fileURLWithPath:@"path/aa.txt"]; NSURLSessionUploadTask *uploadTask=[manager uploadTaskWithRequest:request fromFile:filePath progress:nil completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) {
if (error) {
NSLog(@"Errof:%@",error);
}else{
NSLog(@"Success:%@ %@",response,responseObject);
}
}];
[uploadTask resume];
} -(void)MultiUpload{ NSMutableURLRequest *request=[[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST" URLString:@"https:example/upload.php" parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
[formData appendPartWithFileURL:[NSURL fileURLWithPath:@"path/1.png"] name:@"file" fileName:@"filename.jpg" mimeType:@"image/jpeg" error:nil];
} error:nil]; AFURLSessionManager *manager=[[AFURLSessionManager alloc]initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]]; NSURLSessionUploadTask *uploadTask; uploadTask=[manager uploadTaskWithStreamedRequest:request progress:^(NSProgress * _Nonnull uploadProgress) {
dispatch_async(dispatch_get_main_queue(), ^{
[[UIProgressView new] setProgress:uploadProgress.fractionCompleted];
});
} completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) {
if (error) {
NSLog(@"errof:%@",error);
}else{
NSLog(@"%@ %@",response,responseObject);
}
}]; [uploadTask resume];
}
// data Task
-(void)dataTask{
NSURLSessionConfiguration *configuration=[NSURLSessionConfiguration defaultSessionConfiguration]; AFURLSessionManager *manager=[[AFURLSessionManager alloc]initWithSessionConfiguration:configuration]; NSURL *url=[NSURL URLWithString:@"http://1.studyios.sinaapp.com/gyxy.php?a=qq"]; NSURLRequest *request=[NSURLRequest requestWithURL:url]; NSURLSessionDataTask *dataTask=[manager dataTaskWithRequest:request completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) {
if (error) {
NSLog(@"Error: %@",error);
}else{
NSLog(@"%@ %@",response,responseObject);
}
}]; [dataTask resume];
}
//GET方法 -(void)Serialization{
NSURLSessionConfiguration *configuration=[NSURLSessionConfiguration defaultSessionConfiguration]; AFURLSessionManager *manager=[[AFURLSessionManager alloc]initWithSessionConfiguration:configuration];
NSString *url=@"http://1.studyios.sinaapp.com/gyxy.php";
NSDictionary *parameters=@{@"a":@"BB",@"b":@"CC",@"c":@"aa"};
NSMutableURLRequest *request= [[AFHTTPRequestSerializer serializer]requestWithMethod:@"GET" URLString:url parameters:parameters error:nil]; NSURLSessionDataTask *dataTask=[manager dataTaskWithRequest:request completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) {
if (error) {
NSLog(@"Error: %@",error);
}else{
NSLog(@"%@",responseObject);
}
}];
[dataTask resume]; }
//POST
-(void)PostMethod{
NSURLSessionConfiguration *configuration=[NSURLSessionConfiguration defaultSessionConfiguration];
AFURLSessionManager *manager=[[AFURLSessionManager alloc]initWithSessionConfiguration:configuration];
NSString *url=@"http://1.studyios.sinaapp.com/mypost.php";
NSDictionary *dic=@{@"can1":@"abc",@"can2":@"bcd"};
NSMutableURLRequest *request=[[AFHTTPRequestSerializer serializer] requestWithMethod:@"POST" URLString:url parameters:dic error:nil];
//
// NSURLSessionDataTask *dataTask=[manager dataTaskWithRequest:request completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) {
if (error) {
NSLog(@"Error: %@",error);
}else{
// NSLog(@"%@",responseObject);
NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
NSLog(@"%@",dic);
}
}];
[dataTask resume]; } -(void)Reacheab{ [[AFNetworkReachabilityManager sharedManager]setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
NSLog(@"reacheability:%@",AFStringFromNetworkReachabilityStatus(status));
}];
[[AFNetworkReachabilityManager sharedManager] startMonitoring];
}
-(void)SSLCertificates{
AFHTTPSessionManager *manager=[AFHTTPSessionManager manager];
manager.securityPolicy.allowInvalidCertificates=YES;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end

AFNetworking 3.0.4 的使用的更多相关文章

  1. AFNetworking 3.0 源码解读 总结(干货)(下)

    承接上一篇AFNetworking 3.0 源码解读 总结(干货)(上) 21.网络服务类型NSURLRequestNetworkServiceType 示例代码: typedef NS_ENUM(N ...

  2. AFNetworking 3.0 源码解读(十一)之 UIButton/UIProgressView/UIWebView + AFNetworking

    AFNetworking的源码解读马上就结束了,这一篇应该算是倒数第二篇,下一篇会是对AFNetworking中的技术点进行总结. 前言 上一篇我们总结了 UIActivityIndicatorVie ...

  3. AFNetworking 3.0 源码解读(十)之 UIActivityIndicatorView/UIRefreshControl/UIImageView + AFNetworking

    我们应该看到过很多类似这样的例子:某个控件拥有加载网络图片的能力.但这究竟是怎么做到的呢?看完这篇文章就明白了. 前言 这篇我们会介绍 AFNetworking 中的3个UIKit中的分类.UIAct ...

  4. AFNetworking 3.0 源码解读(九)之 AFNetworkActivityIndicatorManager

    让我们的APP像艺术品一样优雅,开发工程师更像是一名匠人,不仅需要精湛的技艺,而且要有一颗匠心. 前言 AFNetworkActivityIndicatorManager 是对状态栏中网络激活那个小控 ...

  5. AFNetworking 3.0 源码解读(八)之 AFImageDownloader

    AFImageDownloader 这个类对写DownloadManager有很大的借鉴意义.在平时的开发中,当我们使用UIImageView加载一个网络上的图片时,其原理就是把图片下载下来,然后再赋 ...

  6. AFNetworking 3.0 源码解读(七)之 AFAutoPurgingImageCache

    这篇我们就要介绍AFAutoPurgingImageCache这个类了.这个类给了我们临时管理图片内存的能力. 前言 假如说我们要写一个通用的网络框架,除了必备的请求数据的方法外,必须提供一个下载器来 ...

  7. AFNetworking 3.0 源码解读(六)之 AFHTTPSessionManager

    AFHTTPSessionManager相对来说比较好理解,代码也比较短.但却是我们平时可能使用最多的类. AFNetworking 3.0 源码解读(一)之 AFNetworkReachabilit ...

  8. AFNetworking 3.0 源码解读(三)之 AFURLRequestSerialization

    这篇就讲到了跟请求相关的类了 关于AFNetworking 3.0 源码解读 的文章篇幅都会很长,因为不仅仅要把代码进行详细的的解释,还会大概讲解和代码相关的知识点. 上半篇: URI编码的知识 关于 ...

  9. AFNetworking 3.0 源码解读(四)之 AFURLResponseSerialization

    本篇是AFNetworking 3.0 源码解读的第四篇了. AFNetworking 3.0 源码解读(一)之 AFNetworkReachabilityManager AFNetworking 3 ...

  10. AFNetworking 3.0 源码解读(五)之 AFURLSessionManager

    本篇是AFNetworking 3.0 源码解读的第五篇了. AFNetworking 3.0 源码解读(一)之 AFNetworkReachabilityManager AFNetworking 3 ...

随机推荐

  1. Android Studio的git功能的使用介绍

    本文介绍Android Studio(下面简称AS)中git工具的一些简单使用.因为AS为git的使用提供了很多人性化的图形界面操作,在很大程度上可以增加开发效率.本文面向新手,题主自己也是新手一枚, ...

  2. [译]针对科学数据处理的统计学习教程(scikit-learn教程2)

    翻译:Tacey Wong 统计学习: 随着科学实验数据的迅速增长,机器学习成了一种越来越重要的技术.问题从构建一个预测函数将不同的观察数据联系起来,到将观测数据分类,或者从未标记数据中学习到一些结构 ...

  3. vue-resource 拦截器使用

    在vue项目使用vue-resource的过程中,临时增加了一个需求,需要在任何一个页面任何一次http请求,增加对token过期的判断,如果token已过期,需要跳转至登录页面.如果要在每个页面中的 ...

  4. Mysql高并发优化

    一.数据库结构的设计 1.数据行的长度不要超过8020字节,如果超过这个长度的话在物理页中这条数据会占用两行从而造成存储碎片,降低查询效率. 2.能够用数字类型的字段尽量选择数字类型而不用字符串类型的 ...

  5. Java递归列出所有文件和文件夹

    package file_op; import java.io.File; public class file_list { static int n =0; /** * @param args */ ...

  6. hibernate----1-1

    <?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hi ...

  7. Scalaz(14)- Monad:函数组合-Kleisli to Reader

    Monad Reader就是一种函数的组合.在scalaz里函数(function)本身就是Monad,自然也就是Functor和applicative.我们可以用Monadic方法进行函数组合: i ...

  8. C# Excel处理工具

    需求:选择一个Excel文件,然后对该Excel文件进行处理,再导出一个处理后的Excel文件. 效果图 声明:我对winform开发不熟,但是我看到许多开发人员做东西只管交差,从不考虑用户体验,也不 ...

  9. POS机刷卡跨行交易的清算方式

    POS机刷卡的参与方比较多.以你在星巴克刷卡为例: 持卡人--你 发卡行--你办这张卡的银行,我们假设是工行 商户--星巴克,我们假设星巴克的账户开在建行 收单行--星巴克的刷卡机的归属银行,假设也是 ...

  10. Quartz.NET开源作业调度框架系列(三):IJobExecutionContext 参数传递

    前面写了关于Quartz.NET开源作业调度框架的入门和Cron Trigger , 这次继续这个系列, 这次想讨论一下Quartz.NET中的Job如何通过执行上下文(Execution Conte ...