NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration]; _session = [NSURLSession sessionWithConfiguration:config delegate:self delegateQueue:[NSOperationQueue mainQueue]]; 主要说一下这个函数参数的意义: /** 参数 1. 配置 config 2. 代理…
NSFileManager.NSURL.NSFileHandle.NSData.NSXMLParser.NSUserDefaults.NSKeyedArchiver.NSKeyedUnarchiver.CoreData.NSFetchRequest.NSEntityDescription.NSPredicate. NSSortDescriptor.UIImagePickerController.AVAudioPlayer.MPMoviePlayerController.NSThread.NSBl…
#import "ViewController.h" @interface ViewController ()<NSURLSessionDelegate, NSURLSessionDownloadDelegate> @property (weak, nonatomic) IBOutlet UIProgressView *progressView; //进度条 @property(nonatomic, strong) NSURLSessionTask *downLoadTas…
1.NSURLSession有三种工作模式 (1)defaultSessionConfiguration(默认):使用的是基于磁盘缓存的持久化策略,Cache,Cookie. (2)ephemeralSessionConfiguration(短暂):该模式不使用磁盘保存任何数据.所有和会话相关的caches,证书,cookies等都被保存在RAM中,因此当程序使会话无效,这些缓存的数据就会被自动清空. (3)backgroundSessionConfigurationWithIdentifier…
#import "ViewController.h" @interface ViewController ()<NSURLSessionDelegate,NSURLSessionTaskDelegate,NSURLSessionDataDelegate> @property (weak, nonatomic) IBOutlet UIImageView *imageView; @property (weak, nonatomic) IBOutlet UIProgressVie…
NSFileManager.NSURL.NSFileHandle.NSData.NSXMLParser.NSUserDefaults.NSKeyedArchiver.NSKeyedUnarchiver.CoreData.NSFetchRequest.NSEntityDescription.NSPredicate. NSSortDescriptor.UIImagePickerController.AVAudioPlayer.MPMoviePlayerController.NSThread.NSBl…
#import "ViewController.h" // ----WebKitFormBoundaryvMI3CAV0sGUtL8tr #define Kboundary @"----WebKitFormBoundaryjv0UfA04ED44AhWx" #define KNewLine [@"\r\n" dataUsingEncoding:NSUTF8StringEncoding] @interface ViewController ()&l…
一:NSURLSessionDownloadTask:实现文件下载:无法监听进度 #import "ViewController.h" @interface ViewController () @end @implementation ViewController -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { [self download]; } //优点:不需要担心…
7.1 涉及知识点(1)实现文件上传的方法 /* 第一个参数:请求对象 第二个参数:请求体(要上传的文件数据) block回调: NSData:响应体 NSURLResponse:响应头 NSError:请求的错误信息 */ NSURLSessionUploadTask *uploadTask = [session uploadTaskWithRequest:request fromData:data completionHandler:^(NSData * __nullable data, N…
原文在此 一.整体介绍 NSURLSession在2013年随着iOS7的发布一起面世,苹果对它的定位是作为NSURLConnection的替代者,然后逐步将NSURLConnection退出历史舞台.现在使用最广泛的第三方网络框架:AFNetworking.SDWebImage等等都使用了NSURLSession.作为iOS开发人员,应该紧随苹果的步伐,不断的学习,无论是软件的更新.系统的更新.API的更新,而不能墨守成规. Session翻译为中文意思是会话,我们知道,在七层网络协议中有物理…