#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
// NSURL
NSURL *url = [NSURL URLWithString:@"http://www.baidu.com"];
// 创建请求
/**
timeoutInterval 超时时间
默认是60秒
SDWebImage 15秒
设置超时时间的时候不要设置太长或者是太短
cachePolicy 缓存策略
NSURLRequestUseProtocolCachePolicy = 0, // 默认的缓存策略
NSURLRequestReloadIgnoringLocalCacheData = 1, // 忽略本地缓存
数据实时性要求比较高的,新闻,股票,QQ空间,微博
NSURLRequestReturnCacheDataElseLoad = 2, // 返回本地缓存,如果没有本地缓存,就加载
NSURLRequestReturnCacheDataDontLoad = 3, // 返回本地缓存,如果没有,不加载了
把请求回来的数据保存到本地数据库sqlite3 远程有个数据库 (离线应用)
*/
NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:0 timeoutInterval:15];
// NSURLSession
// 异步发送
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) {
NSLog(@"%@",response);
NSLog(@"%@",NSHomeDirectory());
}];
}
@end
网络:NSURLConnection 缓存
最新推荐文章于 2019-07-08 15:09:39 发布