- 浏览: 763522 次
- 性别:
- 来自: 天堂
文章分类
最新评论
-
xiaozhao-521:
呀呀呀呀呀呀呀
RequestTest222 -
Andy_hyh:
打扰了,问下openmeeting源码可以运行起来吗?
Openmeetings安装 详细步骤 -
qindongliang1922:
擦,现在还行么,厉害
北京免费吃饭的地方 -
minixx77:
...
Openmeetings安装 详细步骤 -
wwwqqqiang:
喜欢楼主分享问题的方式,有思想
UIView 和 CALayer的那点事
一:url 缓存策略
NSURLRequest
requestWithURL:cachePolicy:timeoutInterval:
1:NSURLRequestUseProtocolCachePolicy
This flag will use the underlying protocol’s caching mechanism if the protocol
supports it.
基础策略
2:NSURLRequestReloadIgnoringLocalCacheData
This flag specifies that the local cached copy of the resource that is about to be
downloaded must be disregarded and the remote cache policy must be effective.
If there is a local copy of the resource, managed by the framework itself, it will be
ignored.
忽略本地缓存
3:NSURLRequestReturnCacheDataElseLoad
This flag specifies that the cached data must be used before attempting to load the
data from the original source. The cached data could be protocol-based cached or
locally cached. If there is no cached data, the data will be downloaded from the
original source.
首先使用缓存,如果没有本地缓存,才从原地址下载
4:NSURLRequestReturnCacheDataDontLoad
This flag specifies that only the local cached data must be used. If the data has not
been cached, the request will fail. This is a great flag to use whenever your application
wants to perform operations in offline mode (such as the Offline Mode in
web browsers).
使用本地缓存,从不下载,如果本地没有缓存,则请求失败。此策略多用于离线操作
5:NSURLRequestReloadIgnoringLocalAndRemoteCacheData
This flag disregards any type of caching involved in the process, local and remote,
and always attempts to download the data from the original source.
无视任何的缓存策略,无论是本地的还是远程的,总是从原地址重新下载
6:NSURLRequestReloadRevalidatingCacheData
This flag specifies that the original source of data must validate the local cache (if
any) before an attempt is made to download the data from the original source. If
there is a copy of the original source cached locally and the remote source specifies
that the cached data is valid, the data won’t be downloaded again. In any other
case, the data will be downloaded from the original source.
如果本地缓存是有效的则不下载。其他任何情况都从原地址重新下载
二:NSURLCache
NSURLCache *urlCache = [NSURLCache sharedURLCache];
In iOS, NSURLCache supports caching data only in memory and not
on disk.
(NSURLCache 仅支持内存缓存,不支持硬盘缓存)
- (void) downloadURL:(NSString *)paramURLAsString{ if ([paramURLAsString length] == 0){ NSLog(@"Nil or empty URL is given"); return; } /* Get the shared URL Cache object. No need to create a new one */ NSURLCache *urlCache = [NSURLCache sharedURLCache]; /* We will store up to 1 Megabyte of data into the cache */ [urlCache setMemoryCapacity:1*1024*1024]; /* For our request, we need an instance of NSURL so let's retrieve that from the string that we created before */ NSURL *url = [NSURL URLWithString:paramURLAsString]; /* And this is our request */ NSMutableURLRequest *request =[NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0f]; /* Try to get a cached response to our request. This might come back as nil */ NSCachedURLResponse *response =[urlCache cachedResponseForRequest:request]; /* Do we have a cached response? */ if (response != nil){ NSLog(@"Cached response exists. Loading data from cache..."); [request setCachePolicy:NSURLRequestReturnCacheDataDontLoad]; } self.connection = nil; /* Start the connection with the request */ NSURLConnection *newConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES]; self.connection = newConnection; [newConnection release]; }
发表评论
-
iOS 自定义UIActionSheet
2012-12-18 16:07 16376一:模态视图 UIActi ... -
UIView 和 CALayer的那点事
2012-11-17 23:51 30632UIView 和 CALayer的那点事 (1 ... -
iOS Open Source : Popover API for iPhone
2012-01-20 15:02 1905http://iphonedevelopertips.com/ ... -
ios 任务、线程、定时器
2011-12-26 18:09 7979一:operations(任务) cocoa提供了三种 ... -
ios NSInvocation简单使用
2011-12-22 16:39 6320在ios直接调用某个对象的消息是方法有两种: 一:perfo ... -
iphone 对Web Services的三种请求方式soap get post
2011-11-09 10:57 6376一:Using SO AP 1.1 POST / ... -
sdk3.2手势实例
2011-11-09 10:11 1704#import <UIKit/UIKit.h>@i ... -
关于iphone 利用hpple解析html的问题
2011-08-04 18:28 2171最近在用happe解析html中的图片。有个翻页操作,如果请 ... -
iphone hpple 解析html,xml
2011-07-19 16:21 2708使用Objective-C解析HTML或者XML,系统自带有两 ... -
激活 iPhone通过 GPRS 连接服务器功能的代码
2011-05-13 15:14 1611如果您的 iPhone 应用里含有连接服务器的功能,也许会遇到 ... -
address book api 图型
2011-04-28 15:51 1108最近要搞地址簿了,整理一下 -
[OmniGraffle]iPhone app原型制作工具
2011-04-06 17:35 3915在写程序之前,我们通常需要做一些mockup出来(不知道款爷有 ... -
自定义uislider 样式
2011-04-04 21:28 3795UIImage *stetchLeftTrack= [[UII ... -
iphone 下AsyncSocket网络库编程
2011-04-02 21:04 7590iphone的标准推荐CFNetwork ... -
进阶AlertView运用 - 登入设计
2011-04-01 17:52 2994说明:示范如何利用AlertView来制作系统登入的介面程式碼 ... -
iPad UIPopoverController弹出窗口的位置和坐标
2011-04-01 17:42 1959优化规则: TodoViewControlle ... -
iPhone系统自动化测试
2011-04-01 17:39 2577首先mac系统是必备的2 安装iPhone SD ... -
iphone上面编写具有root权限的程序
2011-04-01 17:31 6244正常途径下, 我们编写的程序发布在App store上, 使用 ... -
聊天。。。。。
2011-04-01 17:13 1056是得分手段 -
iOS开发基础:Modal View Controller的不同呈现方式
2011-04-01 16:40 2776ModalViewController可以有不同的呈现方式(m ...
相关推荐
在IOS应用程序开发中,为了减少与服务端的交互...NSURLRequest需要一个缓存参数来说明它请求的url何如缓存数据的,我们先看下它的CachePolicy类型。 1、NSURLRequestUseProtocolCachePolicy NSURLRequest默认的cac
http NSMutableURLRequest
这是NSURLCache子类,用于处理使用NSURLRequest的所有Web请求。 (包括UIWebView) EVURLCache用于处理以下缓存策略: 即使没有互联网连接,该应用程序也必须能够正常运行。 从应用商店下载应用后,该应用必须立即...
2、应用场景: 2.1、 自定义请求头的HTTPHeaderField 2.2、针对NSURLSessionConfiguration设置代理IP和端口,让一些特殊的请求走自定义的隧道IP和端口 ... 通过[NSURLProtocol registerClass: [NetworkInject class]];...
NSURLProtocol能够让你去重新定义苹果的URL加载系统 (URL Loading System)的行为,URL Loading System里有许多类用于处理URL请求,比如NSURL,NSURLRequest,NSURLConnection和NSURLSession等,当URL Loading System...
NSURLProtocol也是苹果众多黑魔法中的一种,能够让你去重新定义苹果的URL加载系统 (URL Loading System)的行为,URL Loading System里有许多类用于处理URL请求,比如NSURL,NSURLRequest,NSURLConnection和...
一个NSURLRequest,一个NSURLConnection,请求结束之后反回用户可路由IP
DTRequestVerifier 用于单元测试的简单、可扩展的 NSURLRequest 验证...NSURLRequest * request = [[ NSURLRequest alloc ] initWithURL: url]; DTRequestVerifier * verifier = [DTRequestVerifier verifier ]; verif
UIWebView的loadRequest可以用来加载一个url地址,它需要一个NSURLRequest参数。我们定义一个方法用来加载url。在UIWebViewDemoViewController中定义下面方法: - (void)loadWebPageWithStrin
iOS webView的加载时序 UIWebView加载顺序: - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { NSLog(@开始...
NSURLRequest *request = [NSURLRequest requestWithURL:url]; 这里有两点需要注意,第一,这个url的字符串是全英文的,如果在字符串中出现了中文,我们就不能直接调用URLWithString:这个方法,而是要先将url字符串...
UIWebView的loadRequest可以用来加载一个url地址,它需要一个NSURLRequest参数。我们定义一个方法用来加载url。在UIWebViewDemoViewController中定义下面方法: 代码如下: – (void)loadWebPageWithString:...
问题描述: iOS9和iOS10用WKWebView加载URL都没有问题,iOS11却是一片空白 可能是用了 NSMutableURLRequest ,... let request = NSURLRequest.init(url: URL.init(string: urlStr)!) self.wkWebView.load(request as UR
// NSURLRequest *request = [NSURLRequest requestWithURL:url]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; [request setURL:url]; //设置请求方式 [request setHTTPMethod:@"GET...
NSURLRequest *request=[NSURLRequest requestWithURL:urlRquest]; NSLog(@"get_begin");//开始get的方法发送数据最好写成GCD的方式 NSURLResponse *response=nil;//获取服务器的响应返回 NSError *error=nil;//...
AB请求管理器关于ABRequestManager 是一个轻量级且可扩展的 iOS/OS X 请求管理器。它只需要 NSURLRequest(或 ... NSURLRequest *request = [ NSURLRequest requestWithURL: someURL]; [request startWithComplete
请求类NSURLRequest NSURLRequest类中常用方法和属性总结: //通过类方法创建默认的请求对象 /* 通过这种方式创建的请求对象 默认使用NSURLRequestUseProtocolCachePolicy缓存逻辑 默认请求超时时限为60s */ + ...
大文件下载 方案一:利用NSURLConnection和它的代理方法,及NSFileHandle(iOS9后不建议使用) 相关变量: @property (nonatomic,strong) ... NSURLRequest *request = [NSURLRequest requestWithURL:ur
这可以通过编辑@"site files/index"来完成: [_browser loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"site files/index" ofType:@"html"]...
VCRURLConnection ...NSURLRequest *request = [ NSURLRequest requestWithURL: url]; // use either NSURLSession or NSURLConnection NSURLSessionDataTask *task = [[ NSURLSession sharedSession ] dataTas