使用webview如何做超时判断
在加载网页时给一个timer定时器,规定超时时间,然后再超时时间的方法中提示超时
如果没有超时,则在webview协议中的“加载完成”方法中 取消timer定时器
- (void)openWebView
{
if (timer) {
[timer invalidate];
}
timer = [NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:@selector(timerFunction) userInfo:nil repeats:NO]; if (!webViewFirst) {
webViewFirst = [[UIWebView alloc] init];
webViewFirst.frame = CGRectMake(, , ivWelcome.frame.size.width, ivWelcome.frame.size.height);
webViewFirst.backgroundColor = [UIColor whiteColor];
webViewFirst.delegate = self;
webViewFirst.hidden = YES;
[webViewFirst loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[kGlobal getLoadingUrl]]]];
[ivWelcome addSubview:webViewFirst];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(, , ivWelcome.frame.size.width, ivWelcome.frame.size.height);
btn.backgroundColor = [UIColor clearColor];
btn.enabled = NO;
[btn addTarget:self action:@selector(initLoginView) forControlEvents:UIControlEventTouchUpInside];
[ivWelcome addSubview:btn];
btnSkip = btn;
}
else {
webViewFirst.hidden = YES;
[webViewFirst reload];
}
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
if (timer) {
[timer invalidate];
}
btnSkip.enabled = YES;
webViewFirst.hidden = NO;
{//添加淡入淡出动画
CATransition *animation = [CATransition animation];
//animation.delegate = self;
// 设定动画时间
animation.duration = 0.7;
// 设定动画快慢(开始与结束时较慢)
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
animation.type = kCATransitionFade;
[webViewFirst.layer addAnimation:animation forKey:@"animation"];
}
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
[self timerFunction];
}
- (void)timerFunction
{
if (timer) {
[timer invalidate];
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"网络不给力,请重试" delegate:kAPPDELEGATE cancelButtonTitle:@"重试" otherButtonTitles:nil];
[alert show];
}
使用webview如何做超时判断的更多相关文章
- webview内部跳转判断
重写webview内的方法 webView.setWebViewClient(new WebViewClient() { @Override // 在点击请求的是链接是才会调用,重写此方法返回true ...
- asp.net 的page 基类页面 做一些判断 可以定义一个基类页面 继承Page类 然后重写OnPreLoad事件
public class BasePage:Page protected override void OnPreLoad(EventArgs e){ base.OnPreLoad(e); ...
- mybatis做if 判断 传入值0 建议最好不要使用值0
mybatis做if 判断 注意:下面这种写法只适用于 id 类型为字符串. <if test="id != null and id != '' "> id = ...
- 使用JSTL的taglib做if判断
背景:使用springmvc做RESTful风格的CRUD时 问题:使用JSTL的taglib做if判断,未能呈现判断后想要的内容 排查过程: 1.先确定了转发到了正确的jsp文件(在jsp页面中增加 ...
- Android WebView播放视频flash(判断是否安装flash插件)
Android WebView播放flash(判断是否安装flash插件) 最近帮一个同学做一个项目,断断续续的一些知识点记录一下.一个页面中有一个WebView,用来播放swf,如果系统中未安装f ...
- 黄聪:C#中WebClient自动判断编码是UTF-8还是GBK,并且有超时判断功能
public class WebDownload : WebClient { private int _timeout; /// <summary> /// 超时时间(毫秒) /// &l ...
- typeof做类型判断时容易犯下的错
学过js同学都知道js的数据类型有 字符串.数字.布尔.Null.Undefined和object(数组.function......) 作为一个初学者我一直认为每个数据类型返回的结果是这样的 typ ...
- 新增 修改,对xx名字或者其他属性做校验判断是否存在
需求描述:页面输入完xxName和xx编码,点击提交,根据两项内容做重复校验(就是看看数据库里有木有相同的) 解决思路:把这两个东西作为查询条件去查,查到有记录,提示已存在,就不执行新增或者修改操作. ...
- [Xamarin] 使用Webview 來做APP (转帖)
有時候,企業要求的沒有這麼多,他原本可能官方網站就已經有支援Mobile Web Design 他只需要原封不動的開發一個APP 也或是,他只是要型錄型,或是問卷調查的型的APP,這時候透過類似像if ...
随机推荐
- 移动js
http://blog.sina.com.cn/s/blog_6553196001015672.html http://blog.sina.com.cn/s/blog_6553196001014vjb ...
- jquery upgrade
http://www.ifanybug.com/article/00125 http://zhidao.baidu.com/question/69399476.html http://www.tmtp ...
- Unity3D中的第三人称镜头的脚本控制
原地址:http://blog.csdn.net/mobanchengshuang/article/details/27591271 好久没有敲Blog了,谢谢大家的留言.关注.私信等支持,但是我好像 ...
- python image模块
Image 模块 Image 模块提供了同名的类用来表示PIL的图像.Image模块还提供了许多工厂(factory)函数,包块从文件加载图像的函数,以及创建新图像的函数. 例子 下面的脚本加 ...
- ASP.NET UpdatePanel实现点击按钮无刷新且执行js脚本
[一篮饭特稀原创,转载请注明出自http://www.cnblogs.com/wanghafan/p/3770779.html] *.aspx: <asp:ScriptManager ID=& ...
- Altium Designer中默认取消重复画线的选项
- yiic 数据库迁移工具
数据库的结构也同源代码一样随着我们开发的进行而不断的发生着改变.在开发过程中,一般的我们需要像管理我们的源代码一样记录下数据库结构的整个变化过程,以便代码还原到指定版本后,数据库能同步的还原到指定的版 ...
- gtest的安装和测试[good]
一.前言 本篇将介绍一些gtest的基本使用,包括下载,安装,编译,建立我们第一个测试Demo工程,以及编写一个最简单的测试案例. 二.下载 如果不记得网址, 直接在google里搜gtest,第一个 ...
- 归纳决策树ID3(Java实现)
先上问题吧,我们统计了14天的气象数据(指标包括outlook,temperature,humidity,windy),并已知这些天气是否打球(play).如果给出新一天的气象指标数据:sunny,c ...
- 【转】为Xcode添加删除行、复制行快捷键
原文网址:http://www.jianshu.com/p/cc6e13365b7e 在使用eclipse过程中,特喜欢删除一行和复制一行的的快捷键.而恰巧Xcode不支持这两个快捷键,再一次的恰巧让 ...