在加载网页时给一个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如何做超时判断的更多相关文章

  1. webview内部跳转判断

    重写webview内的方法 webView.setWebViewClient(new WebViewClient() { @Override // 在点击请求的是链接是才会调用,重写此方法返回true ...

  2. asp.net 的page 基类页面 做一些判断 可以定义一个基类页面 继承Page类 然后重写OnPreLoad事件

    public class BasePage:Page protected override void OnPreLoad(EventArgs e){     base.OnPreLoad(e);    ...

  3. mybatis做if 判断 传入值0 建议最好不要使用值0

    mybatis做if 判断 注意:下面这种写法只适用于 id 类型为字符串. <if test="id != null and id != '' ">     id = ...

  4. 使用JSTL的taglib做if判断

    背景:使用springmvc做RESTful风格的CRUD时 问题:使用JSTL的taglib做if判断,未能呈现判断后想要的内容 排查过程: 1.先确定了转发到了正确的jsp文件(在jsp页面中增加 ...

  5. Android WebView播放视频flash(判断是否安装flash插件)

    Android WebView播放flash(判断是否安装flash插件)  最近帮一个同学做一个项目,断断续续的一些知识点记录一下.一个页面中有一个WebView,用来播放swf,如果系统中未安装f ...

  6. 黄聪:C#中WebClient自动判断编码是UTF-8还是GBK,并且有超时判断功能

    public class WebDownload : WebClient { private int _timeout; /// <summary> /// 超时时间(毫秒) /// &l ...

  7. typeof做类型判断时容易犯下的错

    学过js同学都知道js的数据类型有 字符串.数字.布尔.Null.Undefined和object(数组.function......) 作为一个初学者我一直认为每个数据类型返回的结果是这样的 typ ...

  8. 新增 修改,对xx名字或者其他属性做校验判断是否存在

    需求描述:页面输入完xxName和xx编码,点击提交,根据两项内容做重复校验(就是看看数据库里有木有相同的) 解决思路:把这两个东西作为查询条件去查,查到有记录,提示已存在,就不执行新增或者修改操作. ...

  9. [Xamarin] 使用Webview 來做APP (转帖)

    有時候,企業要求的沒有這麼多,他原本可能官方網站就已經有支援Mobile Web Design 他只需要原封不動的開發一個APP 也或是,他只是要型錄型,或是問卷調查的型的APP,這時候透過類似像if ...

随机推荐

  1. opencv for python 之 突出点检测

    opencv下载地址:http://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.4.3/OpenCV-2.4.3.exe/dow ...

  2. Spring3 +mybatis3 之 MapperScannerConfigurer

    之前一直使用"org.mybatis.spring.mapper.MapperFactoryBean"这个类在spring中配置mybatis的dao接口,后来发现如果dao太多话 ...

  3. table 表头固定

    <html> <head> <title>Test</title> <style type="text/css"> .d ...

  4. 131. Palindrome Partitioning

    题目: Given a string s, partition s such that every substring of the partition is a palindrome. Return ...

  5. my sql 实现批量操作及注意问题

    使用in来实现批量操作是个很不错的想法: /*实现查询*/ select * from goods where goodsid in (102,103); /*实现批理删除*/ delete from ...

  6. CSS学习笔记——定位position属性的学习

    今天学习之前剩下的一个问题:CSS的position属性.首先归纳出和position相关的问题: position作为一个属性,它一共有哪几个属性值? position常用的属性值有哪几个?分别有什 ...

  7. MVC View基础

    View主要用于呈现数据.由于Controller和相关的Service已经处理完业务逻辑并将结果打包成model实体,View只需要怎么去获得model并将其转为Html 1选择需要渲染的视图 在上 ...

  8. Eclipse反编译插件: Jodeclipse与JadClipse

    Eclipse反编译插件: Jodeclipse与JadClipse Jodeclipse 是Jode的Eclipse插件,JadClipse是Jad的Eclipse插件,它们都是非常好的反编译插件. ...

  9. LightOJ 1245 Harmonic Number (II) 水题

    分析:一段区间的整数除法得到的结果肯定是相等的,然后找就行了,每次是循环一段区间,暴力 #include <cstdio> #include <iostream> #inclu ...

  10. 使用 Visual Studio 分析器找出应用程序瓶颈(转)

    使用 Visual Studio 分析器找出应用程序瓶颈 Hari Pulapaka and Boris Vidolov 本文讨论: 以性能瓶颈为目标 应用程序代码分析 比较分析数据 性能报告 本文使 ...