本文永久链接: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. JS 实现可停顿的垂直滚动

    var ScrollMiddle = { 'Odiv':document.getElementById('comment'), // 目标DOM 'Oli': document.getElementB ...

  2. The Web server is configured to not list the contents of this directory.

    部署一个ASP.NET MVC网站至一个全新的服务器Windows Server 2008 R2, 数据为MS SQL Server 2014 64bit Expression版本. 运行时,它第一次 ...

  3. iOS的QuickTime Plugin

    当UIWebView播放视频时,可以看到view hierarchy里有FigPluginView的身影.这个类来自于QuickTime Plugin,plugin的路径为: /Application ...

  4. ActionSupport与action区别

    action是接口,只有一个execute方法需要实现.ActionSupport是action接口的一个实现类.这个类除了实现action接口还实现了Validateable(用于验证)等接口,开发 ...

  5. vim快捷键整理(转载)

    一.移动光标 1.左移h.右移l.下移j.上移k2.向下翻页ctrl + f,向上翻页ctrl + b3.向下翻半页ctrl + d,向上翻半页ctrl + u4.移动到行尾$,移动到行首0(数字), ...

  6. 2016暑假多校联合---To My Girlfriend

    2016暑假多校联合---To My Girlfriend Problem Description Dear Guo I never forget the moment I met with you. ...

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

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

  8. C语言的关键字,运算符,标识符

    关键字 数据类型修饰相关 auto按照自动的方式进行变量的存储 const定义常量或常参数 extern声明外部变量或函数 register指定变量的存储类型是寄存器变量 static指定变量的存储类 ...

  9. phpcms 移植【添加相关文章】功能

    添加相关文章功能相当有用,移植一个过来基本上可以实现比较复杂的页面内包含分类功能,做二次开发时可以省下不少力气. 用例:如果一个产品,属于一个厂家,而这个厂家是动态添加的,既不是一个分类,而是一个厂家 ...

  10. php学习5-时间和日期

    如果时间时区不对,使用时间是要先设定时区,使用date_default_timezone_set() 设置新时区 date_default_timezone_set('Asia/Shanghai'); ...