<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>WKWebView &#8211; 编程技术记录</title>
	<atom:link href="https://blog.z6z8.cn/tag/wkwebview/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.z6z8.cn</link>
	<description>世界你好!</description>
	<lastBuildDate>Tue, 11 Feb 2020 08:47:54 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.3</generator>
	<item>
		<title>WKWebView ： html的input控件的onfocus事件被触发了两次</title>
		<link>https://blog.z6z8.cn/2020/02/11/html%e7%9a%84input%e6%8e%a7%e4%bb%b6%e7%9a%84onfocus%e4%ba%8b%e4%bb%b6%e8%a2%ab%e8%a7%a6%e5%8f%91%e4%ba%86%e4%b8%a4%e6%ac%a1/</link>
		
		<dc:creator><![CDATA[holdsky]]></dc:creator>
		<pubDate>Tue, 11 Feb 2020 08:47:54 +0000</pubDate>
				<category><![CDATA[iOS]]></category>
		<category><![CDATA[学习笔记]]></category>
		<category><![CDATA[WKWebView]]></category>
		<guid isPermaLink="false">http://blog.z6z8.cn/?p=791</guid>

					<description><![CDATA[环境: iOS 13.2 + WKWebView 现象一： 当不添加viewport时,onfocus被触发一 [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>环境:</p>
<ul>
<li>iOS 13.2  + WKWebView</li>
</ul>
<p>现象一：<br />
当不添加<code>viewport</code>时,onfocus被触发一次</p>
<pre><code class="language-html">&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;head&gt;
        &lt;script&gt;
            function onfocus123(e){
                console.log(456);
            }
        &lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;span&gt;test_input&lt;/span&gt;
        &lt;input id="test_input" type="text" onfocus="onfocus123(event)"&gt;
    &lt;/body&gt;
&lt;/html&gt;</code></pre>
<table>
<thead>
<tr>
<th>第一次点击input输入框</th>
<th>第二次点击input输入框</th>
</tr>
</thead>
<tbody>
<tr>
<td>输出：456</td>
<td>输出: 456</td>
</tr>
</tbody>
</table>
<p>现象一：<br />
当添加<code>viewport</code>时,onfocus被触发两次</p>
<pre><code class="language-html">&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;head&gt;
        &lt;script&gt;
            function onfocus123(e){
                console.log(456);
            }
        &lt;/script&gt;
        &lt;meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0, minimum-scale=1.0, viewport-fit=cover,user-scalable=no"&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;span&gt;test_input&lt;/span&gt;
        &lt;input id="test_input" type="text" onfocus="onfocus123(event)"&gt;
    &lt;/body&gt;
&lt;/html&gt;</code></pre>
<table>
<thead>
<tr>
<th>第一次点击input输入框</th>
<th>第二次点击input输入框</th>
</tr>
</thead>
<tbody>
<tr>
<td>输出：456  456</td>
<td>输出: 456</td>
</tr>
</tbody>
</table>
<p>暂时没有比较好的解决办法。</p>
<p>另，参考https://patrickhlauke.github.io/touch/tests/results/，</p>
<pre><code>There is some oddity/bug in iOS 12.2, with ,  and  being fired twice when first tapping on the control. The experimental WebKit feature for pointer events also generates some duplicate pointerup events.</code></pre>
<p>可知，基于WebKit的浏览器如WKWebView,Safari，在一些版本上（如12.2）会有奇怪的bug,事件<code>mousedown</code>、<code>mouseup</code>、<code>click</code>在第一次进入控件时会被触发两次。</p>
<p>其他相关讨论可见https://greensock.com/forums/topic/21397-ios-13-safariwkwebview-draggable-double-dispatching-click-events/</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Could not signal service com.apple.WebKit.WebContent: 113: Could not find specified service</title>
		<link>https://blog.z6z8.cn/2019/11/07/could-not-signal-service-com-apple-webkit-webcontent-113-could-not-find-specified-service/</link>
					<comments>https://blog.z6z8.cn/2019/11/07/could-not-signal-service-com-apple-webkit-webcontent-113-could-not-find-specified-service/#respond</comments>
		
		<dc:creator><![CDATA[holdsky]]></dc:creator>
		<pubDate>Thu, 07 Nov 2019 07:18:27 +0000</pubDate>
				<category><![CDATA[iOS]]></category>
		<category><![CDATA[学习笔记]]></category>
		<category><![CDATA[WKWebView]]></category>
		<guid isPermaLink="false">http://blog.z6z8.cn/?p=547</guid>

					<description><![CDATA[接手一个项目，Debug运行后打开WKWebView的页面，Xcode报出日志 Could not signa [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>接手一个项目，Debug运行后打开WKWebView的页面，Xcode报出日志</p>
<pre><code>Could not signal service com.apple.WebKit.WebContent: 113: Could not find specified service</code></pre>
<p>解决办法：<br />
<code>在WKWebView在Window上显示之前，不要加载网页</code><br />
直白的代码如下：</p>
<pre><code class="language-objc">[self.view addSubView:wkwebView];
[wkwebView loadRequest:request]</code></pre>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.z6z8.cn/2019/11/07/could-not-signal-service-com-apple-webkit-webcontent-113-could-not-find-specified-service/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>WKWebView：适配H5页面的显示尺寸</title>
		<link>https://blog.z6z8.cn/2019/11/04/wkwebview%ef%bc%9a%e9%80%82%e9%85%8dh5%e9%a1%b5%e9%9d%a2%e7%9a%84%e6%98%be%e7%a4%ba%e5%b0%ba%e5%af%b8/</link>
					<comments>https://blog.z6z8.cn/2019/11/04/wkwebview%ef%bc%9a%e9%80%82%e9%85%8dh5%e9%a1%b5%e9%9d%a2%e7%9a%84%e6%98%be%e7%a4%ba%e5%b0%ba%e5%af%b8/#respond</comments>
		
		<dc:creator><![CDATA[holdsky]]></dc:creator>
		<pubDate>Mon, 04 Nov 2019 03:29:01 +0000</pubDate>
				<category><![CDATA[iOS]]></category>
		<category><![CDATA[学习笔记]]></category>
		<category><![CDATA[布局]]></category>
		<category><![CDATA[WKWebView]]></category>
		<guid isPermaLink="false">http://blog.z6z8.cn/?p=544</guid>

					<description><![CDATA[一般的同样的html代码，在UIWebView和WKWebView中显示效果是不一样的。例如 &#60;!DOC [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>一般的同样的html代码，在UIWebView和WKWebView中显示效果是不一样的。例如</p>
<pre><code class="language-html">&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;body&gt;
        &lt;span&gt;test_input&lt;/span&gt;
        &lt;input id="test_input" type="text"&gt;
    &lt;/body&gt;
&lt;/html&gt;</code></pre>
<p>显示效果：<img decoding="async" src="/wp-content/uploads/2019/11/wkwebview_uiwebview.png" alt="" /></p>
<p>可以看出两者有明显的区别。<br />
那么如何适配呢？有两个方法（本质上是一个）。<br />
1、如果是H5适配WKWebView的话，需要在H5添加如下代码</p>
<pre><code class="language-html">&lt;meta name="viewport" content="width=device-width"&gt;</code></pre>
<p>完整的html如下</p>
<pre><code class="language-html">&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;head&gt;
        &lt;meta name="viewport" content="width=device-width"&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;span&gt;test_input&lt;/span&gt;
        &lt;input id="test_input" type="text"&gt;
    &lt;/body&gt;
&lt;/html&gt;</code></pre>
<p>2、如果是WKWebView适配H5的话，那么就需要替前端添加相同的H5代码，实现如下</p>
<pre><code class="language-swift"> //js代码，在文档加载完毕后，添加head的子节点
 //节点内容为&lt;meta name="viewport" content="width=device-width"&gt;
        let jScript = "var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'width=device-width'); document.getElementsByTagName('head')[0].appendChild(meta);";
        let wkUScript = WKUserScript.init(source: jScript, injectionTime: WKUserScriptInjectionTime.atDocumentEnd, forMainFrameOnly: true);
        let wkUController = WKUserContentController.init();
        wkUController.addUserScript(wkUScript);

        let wkconfig = WKWebViewConfiguration.init();
        wkconfig.userContentController = wkUController;

        _webView = WKWebView.init(frame: CGRect.init(x: 0, y: 0, width: self.view.bounds.size.width, height: self.view.bounds.size.height), configuration: wkconfig);
        self.view.addSubview(_webView);

        let htmlfile = Bundle.main.path(forResource: "test", ofType: ".html");
        let url = URL.init(fileURLWithPath: htmlfile!);
        let request = URLRequest.init(url: url);
        _webView.load(request);</code></pre>
<p>参考 <a href="https://blog.csdn.net/GYMotgm/article/details/77944163">https://blog.csdn.net/GYMotgm/article/details/77944163</a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.z6z8.cn/2019/11/04/wkwebview%ef%bc%9a%e9%80%82%e9%85%8dh5%e9%a1%b5%e9%9d%a2%e7%9a%84%e6%98%be%e7%a4%ba%e5%b0%ba%e5%af%b8/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
