美文网首页
NSURLCache

NSURLCache

作者: 我是小胡胡123 | 来源:发表于2017-08-16 19:28 被阅读5次

cache
1、afnetworking默认的NSURLSessionConfiguration

    NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];

    //TODO set the default HTTP headers

    configuration.HTTPShouldSetCookies = YES;
    configuration.HTTPShouldUsePipelining = NO;

    configuration.requestCachePolicy = NSURLRequestUseProtocolCachePolicy;
    configuration.allowsCellularAccess = YES;
    configuration.timeoutIntervalForRequest = 60.0;
    configuration.URLCache = [AFImageDownloader defaultURLCache]; // NSURLCache
    return configuration;



+ (NSURLCache *)defaultURLCache {
    return [[NSURLCache alloc] initWithMemoryCapacity:20 * 1024 * 1024
                                         diskCapacity:150 * 1024 * 1024
                                             diskPath:@"com.alamofire.imagedownloader"];
}

2、系统默认的NSURLSessionConfiguration

    if (!configuration) {
        configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
    }


[NSURLSession sessionWithConfiguration:self.sessionConfiguration delegate:self delegateQueue:self.operationQueue]


3、UIWebView
UIWebView+AFNetworking// 替换UIWebView加载网页的默认的方法- (void)loadRequest:(NSURLRequest *)request;

用NSURLSession下载数据,然后用UIWebview下面的方法加载URLSession加载成的数据


- (void)loadData:(NSData *)data MIMEType:(NSString *)MIMEType textEncodingName:(NSString *)textEncodingName baseURL:(NSURL *)baseURL; 




    NSURLSessionDataTask *dataTask;
    dataTask = [self.sessionManager
            GET:request.URL.absoluteString
            parameters:nil
            progress:nil
            success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject) {
                __strong __typeof(weakSelf) strongSelf = weakSelf;
                if (success) {
                    success((NSHTTPURLResponse *)task.response, responseObject);
                }
                [strongSelf loadData:responseObject MIMEType:MIMEType textEncodingName:textEncodingName baseURL:[task.currentRequest URL]];

                if ([strongSelf.delegate respondsToSelector:@selector(webViewDidStartLoad:)]) {
                    [strongSelf.delegate webViewDidFinishLoad:strongSelf];
                }
            }
            failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
                if (failure) {
                    failure(error);
                }
            }];
    self.af_URLSessionTask = dataTask;


相关文章

  • NSURLCache官方文档阅读

    NSURLCache Overview NSURLCache类通过将NSURLRequest对象映射到NSCach...

  • [iOS-Foundation] Networking Cach

    NSHipster-NSURLCache NSURLCache 通过保存NSURLRequest对象和其相应的NS...

  • iOS网络请求缓存 - NSURLCache

    NSURLCache NSURLCache为应用程序的URL请求提供复合的内存和磁盘缓存机制。作为Foundati...

  • NSCache & NSDictionary &

    NSCache和NSURLCache一点关系也没有 NSCache和NSURLCache一点关系也没有 NSURL...

  • NSURLCache

    NSURLCache 为应用的 URL 请求提供了内存以及磁盘上的缓存。当一个请求完成下载来自服务器的回应,一个缓...

  • NSURLCache

    cache1、afnetworking默认的NSURLSessionConfiguration 2、系统默认的NS...

  • NSURLCache

    概述 NSURLCache类通过将NSURLRequest对象映射到NSCached URLResponse对象来...

  • NSURLCache

    NSURLCache FrameworkFoundation SDKsiOS 8.0+macOS 10.10+tv...

  • NSURLCache

    NSURLCache为你的url请求提供了内存以及磁盘上的综合缓存机制。使用缓存可以减少向服务发送请求的次数,同时...

  • NSURLCache

    缘由 前一段时间去仿写SDWebImage的时候,就遇到这SDCache和NSURLCache,然后在类中还有地做...

网友评论

      本文标题:NSURLCache

      本文链接:https://www.haomeiwen.com/subject/lrkwrxtx.html