ios uiwebviewios 支持 ipv6ipv6吗

UIWebView解决加载页面时背景一片空白问题 - CSDN博客
UIWebView解决加载页面时背景一片空白问题
UIWebView加载过程中,在页面没有加载完毕前,会显示一片空白。为解决这个问题,方法如下:
方法1、让UIWebView背景透明。
webView.backgroundColor = [UIColor clearColor];
webView.opaque = NO;
[webView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@&webbg.png&]]];
先将webView的frame设为0, 在页面加载完成后再将frame设为原来大小.
在viewDidLoad中,在WebView上面覆盖一个背景视图。
self.webView=[[[UIWebView alloc]initWithFrame:self.view.bounds]autorelease];
[self.webView loadRequest:request];
[self.view addSubview:self.webView];
UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@&gatewaybg.png&]];
imageView.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
[self.view addSubview:imageView];
然后在WebView加载完成后把视图放到最上层或移除背景视图。
- (void)webViewDidFinishLoad:(UIWebView *)webView
// WebView放到最上层
[self.view bringSubviewToFront:self.webView];
// 或者可以把背景图移除
[self.webView removeFromSuperview];
本文已收录于以下专栏:
相关文章推荐
在使用WebView控件将网页嵌入应用的时候有时会遇到页面显示不出来或者显示为空白页的情况,以下为解决方案:
webView = (WebView) findViewById(R.id.id...
UIWebView 加载后为空白页在使用 UIWebView的loadRequest 之后页面显示为空白页,原因是很简单,其实可以使用的 UIWebView的 delegate方法来输出它的错误原因....
近日工程中有用到webview加载网页,有两个入口可以进入到含有webview的controller, 打开webView的URL中含有中文字段,加载后webView显示白屏,后来发现iOS webV...
最近在使用WebView进行网页内容显示时,如果网络很慢,例如2G网络,加载网页会需要很长时间,在加载过程中,WebView一直显示白屏,体验不是很好。经过修改可以使用以下几个方案解决WebView加...
最近在使用WebView进行网页内容显示时,如果网络很慢,例如2G网络,加载网页会需要很长时间,在加载过程中,WebView一直显示白屏,体验不是很好。经过修改可以使用以下几个方案解决WebView加...
1、WKWebView 自诩拥有更快的加载速度,更低的内存占用,但实际上 WKWebView 是一个多进程组件,Network Loading 以及 UI Rendering 在其它进程中执行。初次适...
http://blog.csdn.net/garybook/article/details/8205974,没怎么细看,添加上属性后效果得以实现,等忙完后再细看时怎么回事吧。
在项目中遇到WebView在加载图片的时候会出现白屏的情况,后来在xml设置了WebView属性,问题的到解决:
android:id=&@+id/webview&
注:文章首次发布于个人博客,现将技术文章转移至此。 http://blog.go3k.org/cocos2dx-add-webview/
游戏中的帮助和游戏公告,可以通过嵌入显示WebVie...
cocostudio动画编辑器中加入粒子效果,cocos2d3.3在播放的时候报错:  The value type isn't Type::MAP
在 CCDataReaderHelper...
他的最新文章
讲师:何宇健
讲师:董岩
您举报文章:
举报原因:
原文地址:
原因补充:
(最多只允许输入30个字)iOS WebView - 简书
iOS WebView
WKWebView 可以参考
UIWebView 缓存
1.这是官方原版的,根据测试有网络直接读网络,没网络才会读本地
/rnapier/RNCachingURLProtocol
2.下面这个是根据我们的需求来修改了一下,我们的需求是有缓存的话,不用再次联网更新的,节约玩家的流量,因为游戏基本是不会修改的,换了连接以后,缓存才会更新,这样就可以实现离线也可以很愉快的玩耍,下次再打开,就秒开啦
/BaiCanLin/RNCachingURLProtocol
UIWebView 的一些注意点
1.当时我们还需要兼容iOS6版本的系统,在iOS6上面,比如分别有A和B两个控制器,分别加载2个UIWebView,只有一个会正常运行,相同的测试在iOS7以上的版本不会有问题。
2.如果打着断点,给WebView调试的时候突然间奔溃了,把断点去掉即可,当初被这个给坑死了,谷歌后才知道
UIWebView利用CocoaHTTPServer开启本地服务器,加载本地资源
1.官方介绍
CocoaHTTPServer is a small, lightweight, embeddable HTTP server for Mac OS X or iOS applications.
Sometimes developers need an embedded HTTP server in their app.Perhaps it's a server application with remote monitoring.Or perhaps it's a desktop application using HTTP for the communication backend.Or perhaps it's an iOS app providing over-the-air access to documents.Whatever your reason, CocoaHTTPServer can get the job done. It provides:
Built in support for bonjour broadcastingIPv4 and IPv6 supportAsynchronous networking using GCD and standard socketsPassword protection supportSSL/TLS encryption supportExtremely FAST and memory efficientExtremely scalable (built entirely upon GCD)Heavily commented codeVery easily extensibleWebDAV is supported too!
2.使用非常简单,照着官方的Demo试一下就行,建议使用cocopods安装
/robbiehanson/CocoaHTTPServer
UIWebView实现自动登陆
/p/072bbc1e4c33?utm_campaign=hugo&utm_medium=reader_share&utm_content=note
让UIWebView 有类似于微信的加载进度条
/ninjinkun/NJKWebViewProgress
UIWebView Javascript进行交互
1.objective-c调用 javascript :
[webView stringByEvaluatingJavaScriptFromString:@"alert('done')"];
2.可以自定义协议,比如一个网页,你想调起原生的应用,可以自定义一个协议,通过UIWebView中的委托 shouldStartLoadWithRequest 方法。
NSString *requestString = [[request URL] absoluteString];
NSArray *components = [requestString componentsSeparatedByString:@"://"];
if ([components count] & 1 && [(NSString *)[components objectAtIndex:0] isEqualToString:@"这里一般写公司域名"]) {
if ([[components lastObject] isEqualToString:@"share"]){
DebugLog(@"监听到 webView 分享");
}else if ([[components lastObject] isEqualToString:@"gameover"]) {
DebugLog(@"监听到 webView 游戏结束");
3.WebViewJavascriptBridge是一个Objective-C与JavaScript进行消息互通的三方库
/marcuswestin/WebViewJavascriptBridge
试试这个库很不错,根据版本号切换iOS7 &-& iOS8
pod 'KINWebBrowser'WKWebView使用遇到的坑 - 简书
WKWebView使用遇到的坑
1. ios9以前版本读取本地HTML的问题
当使用loadRequest来读取本地的HTML时,WKWebView是无法读取成功的,后台会出现如下的提示:Could not create a sandbox extension for /原因是WKWebView是不允许通过loadRequest的方法来加载本地根目录的HTML文件。而在iOS9的SDK中加入了以下方法来加载本地的HTML文件:[WKWebView loadFileURL:allowingReadAccessToURL:]但是在iOS9以下的版本是没提供这个便利的方法的。以下为解决方案的思路,就是在iOS9以下版本时,先将本地HTML文件的数据copy到tmp目录中,然后再使用loadRequest来加载。但是如果在HTML中加入了其他资源文件,例如js,css,image等必须一同copy到temp中。这个是最蛋疼的事情了。
解决方法如下
1.Objective-C:
//将文件copy到tmp目录
- (NSURL *)fileURLForBuggyWKWebView8:(NSURL *)fileURL {
NSError *error =
if (!fileURL.fileURL || ![fileURL checkResourceIsReachableAndReturnError:&error]) {
// Create "/temp/www" directory
NSFileManager *fileManager= [NSFileManager defaultManager];
NSURL *temDirURL = [[NSURL fileURLWithPath:NSTemporaryDirectory()] URLByAppendingPathComponent:@"www"];
[fileManager createDirectoryAtURL:temDirURL withIntermediateDirectories:YES attributes:nil error:&error];
NSURL *dstURL = [temDirURL URLByAppendingPathComponent:fileURL.lastPathComponent];
// Now copy given file to the temp directory
[fileManager removeItemAtURL:dstURL error:&error];
[fileManager copyItemAtURL:fileURL toURL:dstURL error:&error];
// Files in "/temp/www" load flawlesly :)
return dstURL;
//调用逻辑
NSString *path = [[NSBundle mainBundle] pathForResource:@"indexoff" ofType:@"html"];
if ([[UIDevice currentDevice].systemVersion floatValue] &= 9.0) {
// iOS9. One year later things are OK.
NSURL *fileURL = [NSURL fileURLWithPath:path];
[self.webView loadFileURL:fileURL allowingReadAccessToURL:fileURL];
// iOS8. Things can be workaround-ed
Brave people can do just this
fileURL = try! pathForBuggyWKWebView8(fileURL)
webView.loadRequest(NSURLRequest(URL: fileURL))
NSURL *fileURL = [self.fileHelper fileURLForBuggyWKWebView8:[NSURL fileURLWithPath:path]];
NSURLRequest *request = [NSURLRequest requestWithURL:fileURL];
[self.webView loadRequest:request];
//将文件copy到tmp目录
func fileURLForBuggyWKWebView8(fileURL: NSURL) throws -& NSURL {
// Some safety checks
var error:NSError? =
if (!fileURL.fileURL || !fileURL.checkResourceIsReachableAndReturnError(&error)) {
throw error ?? NSError(
domain: "BuggyWKWebViewDomain",
code: 1001,
userInfo: [NSLocalizedDescriptionKey: NSLocalizedString("URL must be a file URL.", comment:"")])
// Create "/temp/www" directory
let fm = NSFileManager.defaultManager()
let tmpDirURL = NSURL.fileURLWithPath(NSTemporaryDirectory()).URLByAppendingPathComponent("www")
try! fm.createDirectoryAtURL(tmpDirURL, withIntermediateDirectories: true, attributes: nil)
// Now copy given file to the temp directory
let dstURL = tmpDirURL.URLByAppendingPathComponent(fileURL.lastPathComponent!)
let _ = try? fileMgr.removeItemAtURL(dstURL)
try! fm.copyItemAtURL(fileURL, toURL: dstURL)
// Files in "/temp/www" load flawlesly :)
return dstURL
//方法调用
var filePath = NSBundle.mainBundle().pathForResource("file", ofType: "pdf")
if #available(iOS 9.0, *) {
// iOS9. One year later things are OK.
webView.loadFileURL(fileURL, allowingReadAccessToURL: fileURL)
// iOS8. Things can be workaround-ed
Brave people can do just this
fileURL = try! pathForBuggyWKWebView8(fileURL)
webView.loadRequest(NSURLRequest(URL: fileURL))
fileURL = try fileURLForBuggyWKWebView8(fileURL)
webView.loadRequest(NSURLRequest(URL: fileURL))
} catch let error as NSError {
print("Error: " + error.debugDescription)
2. WKWebView - WKNavigationDelegate使用
特别提醒一点,在使用以下delegate的方法时
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler
需执行decisionHandler的block。
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
NSURLRequest *request = navigationAction.
WMPageActionType actionType = ActionTypeN
WKNavigationActionPolicy actionPolicy = WKNavigationActionPolicyA
if([request.URL.absoluteString hasPrefix:OC_CLOSE_REQUEST]){
actionType = ActionTypeC
actionPolicy = WKNavigationActionPolicyC
if(self.actionDelegate && [self.actionDelegate respondsToSelector:@selector(webView:action:type:)]) {
[self.actionDelegate webView:webView action:navigationAction type:actionType];
//这句是必须加上的,不然会异常
decisionHandler(actionPolicy);
3.WKWebView-JS执行方法
WKWebView JS执行方法与UIWebView不一样了。
- (void)evaluateJavaScript:(NSString *)javaScriptString completionHandler:(void (^)(id, NSError *))completionH
completionHandler 拥有两个参数,一个是返回错误,一个可以返回执行脚本后的返回值

我要回帖

更多关于 ios 项目支持ipv6 的文章

 

随机推荐