关于 UIWebView 加载后为空白页
来源:互联网 发布:小小食杂铺 知乎 编辑:程序博客网 时间:2024/05/17 01:24
UIWebView 加载后为空白页
在使用 UIWebView的loadRequest 之后页面显示为空白页,原因是很简单,其实可以使用的 UIWebView的 delegate方法来输出它的错误原因.
- (void)webView:(UIWebView *)webView didFailLoadWithError:(nullable NSError *)error;
参数error 就是WebView 的提示错误.一般情况都是 url不正确导致的,可以用浏览器试试 URL是否正确,不正确那么就可能是 url含有特殊字符,没有将 url转码之前是使用
- (nullable NSString *)stringByAddingPercentEscapesUsingEncoding:(NSStringEncoding)enc NS_DEPRECATED(10_0, 10_11, 2_0, 9_0, "Use -stringByAddingPercentEncodingWithAllowedCharacters: instead, which always uses the recommended UTF-8 encoding, and which encodes for a specific URL component or subcomponent since each URL component or subcomponent has different rules for what characters are valid.");
从 iOS9以后就废弃这个方法使用下面新的方法
- (nullable NSString *)stringByAddingPercentEncodingWithAllowedCharacters:(NSCharacterSet *)allowedCharacters NS_AVAILABLE(10_9, 7_0);
里面的参数 allowedCharacters 有这么几种
- URLUserAllowedCharacterSet
user 用户 - URLPasswordAllowedCharacterSet
password 密码 - URLHostAllowedCharacterSet
host 主机 - URLPathAllowedCharacterSet
path 路径 - URLQueryAllowedCharacterSet
query 问号 - URLFragmentAllowedCharacterSet
fragment 片段,碎片
我所用的 url 里面包含片段,因此我用了URLFragmentAllowedCharacterSet,下面是扣德
NSURL *loadUrl = [NSURL URLWithString:[<#encoding url#> stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]]];
———- 继续更新
1 0
- 关于 UIWebView 加载后为空白页
- UIWebView显示空白页
- Android升级到7.0使得webview加载页面为空白页
- 关于webview不显示H5内容,加载完成是空白页
- php 加密后空白页
- uiwebview加载网页后根据内容设置大小
- APP中 UIWebView加载网页后,…
- CSS 导致 UIWebView 加载后无法获取高度
- jsp页面打开为空白页
- 关于UItableViewCell上加载UIWebView自适应高度问题
- 关于UIWebView
- 关于UIWebView
- 隐藏TabBar后,UIWebView加载过程中和加载失败时,底部出现黑边的问题解决
- Android WebView 加载网页只显示空白页
- Android 7.0 WebView加载https出现空白页
- Android webview加载H5空白页问题
- UIWebView加载html
- uiwebView 加载html字符串
- 深度学习(四)卷积神经网络Lenet-5实现
- bzoj2012[hnoi2005]狡猾的商人
- mingw(gcc)编译openjpeg
- ViewPager的使用2
- iOS 自定义TabBarController
- 关于 UIWebView 加载后为空白页
- 深度学习(五)caffe环境搭建
- 系统中打开GPS和关闭GPS
- 用回调解决angular service 异步传输数据到controller中
- opencv编程笔记
- iOS导航栏的translucent属性
- webx返回json类型数据
- 21.Merge Two Sorted Lists
- 深度学习(六)caffe入门学习