cordova:8.1.1
cordova-ios:4.5.4
某个changeset(修复问题:ios app中内嵌youtube播放器无法显示)的内容如下:
添加上述修改后,在iOS上点击以下链接,链接没有在safari上打开,什么都不发生:
config.xml中的内容修改为:
<allow-intent>
控制app能打开哪些链接。看起来是<allow-navigation>
中的通配符写法写错了,影响了<allow-intent>
。
找到这么一个issue: allow navigation breaks allow intent ? · Issue #499 · apache/cordova-ios
关于allow-navigation与allow-intent的关系,只在 apache/cordova-plugin-whitelist: Apache Cordova plugin whitelist 中找到这么一句:
但是cordova-plugin-whitelist只是给cordova-android用的,不知道这句话是否适用于cordova-ios。
根据 「<access>
and <allow-navigation>
to (ATS) 」的结果来看,<allow-navigation>
中写错通配符,只是少生成了一些ATS条目。
cordova-ios中和<allow-navigation>
有关的代码是这个 cordova-ios/CDVIntentAndNavigationFilter.m at a5e2fbaaa4d3e75e6cf10135569e58826dc29d47 · apache/cordova-ios,怀疑可能這里面有什么逻辑在<allow-navigation>
写错通配符时拦截了打开链接操作。
按顺序读以下文档:
要点:
<access>
、<allow-navigation>
和<allow-intent>
的用法说明写在cordova-plugin-whitelist的文档中,但它们在cordova-ios上也有用,也要设置。<access>
: Controls which network requests (images, XHRs, etc) are allowed to be made (via cordova native hooks).Note: We suggest you use a Content Security Policy (see below), which is more secure. This whitelist is mostly historical for webviews which do not support CSP.<allow-navigation>
: Controls which URLs the WebView itself can be navigated to. Applies to top-level navigations only. By default navigations are only allowed to file:// URLs. To allow others URLs, you must add <allow-intent>
: Controls which URLs the app is allowed to ask the system to open.<access>
and <allow-navigation>
tags to the appropriate Application Transport Security (ATS) directives which are new in iOS 9. 具体看后文「 <access>
and <allow-navigation>
to (ATS) 」图。<access>
and <allow-navigation>
to (ATS) 转换代码在这里:
打不开链接的:
能打开链接的: