现在在接触iOS开发,今天在调试一个界面加载web页面的问题,发现死活无法加载,浏览器里能正常打开,加上相应代码之后得到了错误信息为:

2013-04-18 15:05:06.446 Client_DEMO[22889:1a303] webview didFailLoadWithError <UIWebView: 0x18ff2160; frame = (18 70; 315 408); autoresize = W+H; layer = <CALayer: 0xc1140a0>> , and err is Error Domain=WebKitErrorDomain Code=101 “The operation couldn’t be completed. (WebKitErrorDomain error 101.)”

加日志的办法为:

WebviewDelegat.h 代码如下:

#import <UIKit/UIKit.h>

@interface WebviewDelegate : NSObject <UIWebViewDelegate>

@end

WebviewDelegat.mm 代码如下:

#import “WebviewDelegate.h”

@implementation WebviewDelegate
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
NSString * str = [[request URL] absoluteString];
NSString *urlStr = [str stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

NSArray * strArray = [urlStr componentsSeparatedByString:@":"];
if([strArray count]>2)
{
NSLog(@”webview for %@”,urlStr);
if ([[strArray objectAtIndex:0] isEqualToString:@”jscall”] ) {
//这里拦截做些本地的事情
}
return NO;
}else{
return YES;
}

}
- (void)webViewDidStartLoad:(UIWebView *)webView{
NSLog(@”webview webViewDidStartLoad %@”,webView.debugDescription);
}
- (void)webViewDidFinishLoad:(UIWebView *)webView{
NSLog(@”webview webViewDidFinishLoad %@”,webView.debugDescription);
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{

//把出错信息打出来
NSLog(@”webview didFailLoadWithError %@ , and err is %@”,webView.debugDescription, error.debugDescription);
}

@end

通过UIWebView的setDelegate方法将其绑定。

网上搜索之后得知是urlencode有问题,仔细核实了一下url,发现url里有个参数值有竖线,于是知道了是竖线未转义导致。

比如: http://lizongbo.com/?chid=0|0|618119, 应该为:http://lizongbo.com/?chid=0%7C0%7C618119

解决办法很简单,对url的字符串做了个替换:

sUrl=replaceStr(sUrl,”|”,”%7C”);//不转义的话会报错,nd err is Error Domain=WebKitErrorDomain Code=101 “The operation couldn’t be completed. (WebKitErrorDomain error 101.)”

参考:http://stackoverflow.com/questions/2028379/uiwebkit-error-101

iOS使用UIWebView遇到Error Domain=WebKitErrorDomain Code=101 “The operation couldn’t be completed. (WebKitErrorDomain error 101的更多相关文章

  1. [ios] 定位报错Error Domain=kCLErrorDomain Code=0 "The operation couldn’t be completed. (kCLErrorDomain error 0.)"

    Error Domain=kCLErrorDomain Code=0 "The operation couldn’t be completed. (kCLErrorDomain error ...

  2. 使用Parse内付费服务出现的Error Domain=Parse Code=146 "The operation couldn’t be completed. (Parse error 146.)

    因为开发一个应用有个内付费去广告功能,介于苹果官方提供的方法没用过,感觉有些复杂,于是选用了第三方组件Parse来解决这个问题,简单易操作: Parse简化苹果官方内付费问题,使用方法分厂简单只有两个 ...

  3. Error Domain=NSOSStatusErrorDomain Code=1718449215 "The operation couldn’t be completed. (OSStatus error 1718449215.)"

    是在录音时,recoreder的录音格式不对.

  4. iOS json 解析遇到error: Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed.

    Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 38 ...

  5. Error Domain=kCLErrorDomain Code=0 "The operation couldn’t be completed.

    地图定位 错误:使用CoreLocation获取地理位置信息,报错 Error Domain=kCLErrorDomain Code=0 "The operation couldn’t be ...

  6. Error Domain=NSURLErrorDomain Code=-999 “The operation couldn’t be completed.

    转:http://www.wangzhengdong.com/blog/error-domainnsurlerrordomain-code-999-the-operation-couldnt-be-c ...

  7. didFailWithError: Error Domain=kCLErrorDomain Code=0 “The operation couldn’t be completed. (kCLError

    This error also occurs if you have Scheme/Edit Scheme/Options/Allow Location Simulation checked but ...

  8. NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)"

    原文: http://stackoverflow.com/questions/19874935/afnetworking-2-0-post-issue-cocoa-error-3840json-tex ...

  9. 【iOS】iOS Error Domain=NSCocoaErrorDomain Code=3840 "未能完成操作。(“Cocoa”错误 3840。)"

    昨天遇到的这个问题,详细信息: ----->类和方法__25+[Manager noticeRequest:]_block_invoke399----->错误信息Error Domain= ...

随机推荐

  1. P1471 方差

    题目 luogu 思路 \[\frac{1}{n}*\sum_{1}^{n}( a_{i}-A)^{2}\] \[\frac{1}{n}*\sum_{1}^{n}( a_{i}^2-2*A*a_{i} ...

  2. sql server文件另存为的时候,选择文件编码和换行

    文件编码 使用code page来标记的,没有找到utf8 without bom 换行

  3. BZOJ1355: [Baltic2009]Radio Transmission KMP

    Description 给你一个字符串,它是由某个字符串不断自我连接形成的. 但是这个字符串是不确定的,现在只想知道它的最短长度是多少. Input 第一行给出字符串的长度,1 < L ≤ 1, ...

  4. HDU 3549 Flow Problem(最大流模板)

    http://acm.hdu.edu.cn/showproblem.php?pid=3549 刚接触网络流,感觉有点难啊,只好先拿几道基础的模板题来练练手. 最大流的模板题. #include< ...

  5. JDK tools之jps和jstack诊断Java程序

    大部分Java开发者可能知道有这么个工具,但是没怎么用过,每次还得百度一下.我也是之一 -_-!!. 每次遇到

  6. 安装labelImage的问题qt

    不知为何需要些source ~/.bash_profile才 自己在 ~/.bash_profile 中配置环境变量, 可是每次重启终端后配置的不生效.需要重新执行 : $source ~/.bash ...

  7. 如何优化myeclipse.

    1.去除不需要加载的模块 一个系统20%的功能往往能够满足80%的需求,MyEclipse也不例外,我们在大多数时候只需要20%的系统功能,所以可以将一些不使用的 模块禁止 加载启动.通过Window ...

  8. 语言小知识-Java ArrayList类 深度解析

    · 问题 1:ArrayList 的 size 和 capacity 怎么理解? 如果把 ArrayList 看作一个杯子的话,capacity 就是杯子的容积,也就是代表杯子能装多少东西,而 siz ...

  9. 批量删除Redis数据库中的Key

    批量删除KeyRedis 中有删除单个 Key 的指令 DEL,但好像没有批量删除 Key 的指令,不过我们可以借助 Linux 的 xargs 指令来完成这个动作 redis-cli keys &q ...

  10. Java 访问权限修饰符以及protected修饰符的理解

    2017-11-04 22:28:39 访问权限修饰符的权限 访问修饰符protected的权限理解 在Core Java中有这样一段话“在Object类中,clone方法被声明为protected, ...