WKWebView如何显示指向http:页面的链接 [英] WKWebView How to display links to http: pages

查看:746
本文介绍了WKWebView如何显示指向http:页面的链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WKWebView,它将使用在线收集的链接显示用户的网页. 有时这些链接是http:,被ATS阻止. 我试过简单地更改到https:的链接,该链接有时会起作用.

I have a WKWebView which will display users' webpages using links gathered online. Sometimes these links are http: which are blocked by ATS. I've tried simply changing the links to https:, which works sometimes.

但是,我经常收到一个错误发生SSL错误,并且无法建立与服务器的安全连接".

However, very often I get an error "An SSL error has occurred and a secure connection to the server cannot be made".

有时页面仅重定向到http:,该页面再次被阻塞. 有时https:页只是找不到". 删除http:仅会导致"Unsupported URL"错误.

Sometimes the page simply redirects to the http:, which gets blocked again. Other times the https: page is simply "Not found". Removing http: only results in "Unsupported URL" error.

有什么办法让WKWebView显示这些页面?

Is there any way to get WKWebView to show these pages?

请不要建议NSAllowsArbitraryLoads,甚至不是每个域的异常(我事先不知道这些域将是什么). 这些页面可以完美地加载到Safari甚至是移动safari上,因此必须可行.

PLEASE DON"T suggest NSAllowsArbitraryLoads, or even per-domain exceptions (I do not know in advance what the domains will be). The pages load perfectly on Safari, and even mobile safari, so it must be possible.

推荐答案

所以,简单的答案是NSAllowsArbitraryLoadsInWebContent,在iOS 10中效果很好.但是,如果尝试在Info.plist中使用iOS 9设备,它将无法正常工作.

So, the short answer is NSAllowsArbitraryLoadsInWebContent, which will work great in iOS 10. However, if you try to run with that in your Info.plist on an iOS 9 device, it won't work.

如果您希望在iOS 9和iOS 10上都可以使用此功能,Apple建议您将两者 NSAllowsArbitraryLoads AND NSAllowsArbitraryLoadsInWebContent您的Info.plist.

If you want this to work on both iOS 9 and iOS 10, what Apple is recommending that you do is to put both NSAllowsArbitraryLoads AND NSAllowsArbitraryLoadsInWebContent in your Info.plist.

在iOS 9中,由于无法识别NSAllowsArbitraryLoadsInWebContent条目,因此它将允许应用程序中的所有http内容(包括WKWebview).这不是理想的选择,但是只要您确保其他地方的关键连接是安全的,让Apple强制执行实际上并没有多大作用.

In iOS 9, since it doesn't recognize the NSAllowsArbitraryLoadsInWebContent entry, it will allow all http content in the app (including your WKWebview). This isn't ideal, but as long as you are ensuring your critical connections elsewhere are secure, having Apple enforce it really doesn't do much.

在iOS 10中(大多数用户应在其中运行),如果iOS 10也显示NSAllowsArbitraryLoadsInWebContent,它将忽略NSAllowsArbitraryLoads.这意味着您的其余应用程序网络通信将需要遵循ATS的安全要求,而WKWebView和UIWebView则不需要.这不是一个很好的解决方案,但是当您需要同时支持iOS 9和10时,这是Apple工程师推荐的解决方案.

In iOS 10 (which most of your users should be running) iOS will ignore the NSAllowsArbitraryLoads if it also sees NSAllowsArbitraryLoadsInWebContent. This means the rest of your app network communications will need to follow ATS's security requirements, while the WKWebView and UIWebView does not. This isn't a great solution, but it is the one recommended by Apple engineers when you need to support both iOS 9 and 10.

请注意,当Apple确实开始要求对ATS例外进行辩护时,NSAllowsArbitraryLoadsInWebContent条目就是将触发对辩护的需求之一.但是,它比单独拥有NSAllowsArbitraryLoads更好,并且您可以将其放在理由中,并且它应该被Apple接受.

Note that when Apple does start to require justifications for ATS exceptions, the NSAllowsArbitraryLoadsInWebContent entry is one of the ones that will trigger the need to justification. But, it is better than having NSAllowsArbitraryLoads by itself, and you can put that in your justification and it should be accepted by Apple.

这篇关于WKWebView如何显示指向http:页面的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆