標籤:style blog http color os 2014
LWTViewController.m
//// 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); }]; }@endView Code