首页 > 其他 > 详细

网络编程练习 -- NSURLCache

时间:2014-07-07 09:42:09      阅读:341      评论:0      收藏:0      [点我收藏+]

LWTViewController.m

bubuko.com,布布扣
//
//  LWTViewController.m
//  网络编程练习 -- NSURLCache
//
//  Created by apple on 14-7-2.
//  Copyright (c) 2014年 lwt. All rights reserved.
//

#import "LWTViewController.h"

@interface LWTViewController ()

@end

@implementation LWTViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSURL *url = [NSURL URLWithString:@"http://192.168.1.24:8080/MJServer/resources/video"];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    
    NSURLCache *cache = [NSURLCache sharedURLCache];
    cache.memoryCapacity = 1024 * 1024;
    cache.diskCapacity = 10 * 1024 * 1024;
    request.cachePolicy = NSURLRequestReturnCacheDataElseLoad;
    
    NSCachedURLResponse *response = [cache cachedResponseForRequest:request];
    if (response) {
        NSLog(@"---这个请求已经存在缓存");
    } else {
        NSLog(@"---这个请求没有缓存");
    }
    
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"%@",dict);
    }];
    
    
}

@end
View Code

 

网络编程练习 -- NSURLCache,布布扣,bubuko.com

网络编程练习 -- NSURLCache

原文:http://www.cnblogs.com/wentianblog/p/3820778.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!