iOS9 白名单问题 -canOpenURL: failed for URL: "xx" - error:"This app is not allowed to query for scheme xx"

【iOS开发】-canOpenURL: failed for URL: "xx" - error:"This app is not allowed to query for scheme xx"

 

Collection/Bookmark/Share for width under 768px

 

控制台输出

 

如图是在我启动一个 Xcode 7 + iOS 9 的 App 之后,控制台的输出。

这在 Xcode 6.4 + iOS 8 时,是不会有的情况,原因是【为了强制增强数据访问安全, iOS9 默认会把所有从NSURLConnectionCFURLNSURLSession发出的 HTTP 请求,都改为 HTTPS 请求:iOS9.x-SDK编译时,默认会让所有从NSURLConnectionCFURLNSURLSession发出的 HTTP 请求统一采用 TLS 1.2(SSL 3.1) 协议。】

下面说解决方案:

①如果你的输出信息是-canOpenURL: failed for URL: "kindle://home" - error: "This app is not allowed to query for scheme kindle"

 

set Bitcode to NO

 

去你的 target 里面的 Build Settings 下的 Enable Bitcode,把它设置成 NO,这不一定会阻挡你的控制台继续输出这条信息,但是可以保证你的 App 正常运行。

②如果你的输出信息是 xxxx - error: "This app is not allowed to query for scheme xxxx"

(在这里因为我的 App 集成了分享到QQ、微信、微博的功能,xxxx部分我看到了 mqq、wechat、sinaweibosso 等多条信息)

 

Info.plist

 

去 Info.plist 里面建立一个叫 LSApplicationQueriesSchemes 的 Array,把你在xxxx部分看到的词汇一个一个填进去,直至控制台没有任何相关输出即可。

③关于其他通过 WebView 访问 http 网址引发的控制台报错信息

 

Info.plist 中设置 ATS

<key>NSAppTransportSecurity</key>

<dict>

<!--Include to allow all connections (DANGER)-->

<key>NSAllowsArbitraryLoads</key>

<true/>

</dict>

如之前所说,Apple 希望我们访问相对安全的 HTTPS,所以在你需要访问 HTTP 时,

虽 Apple 不建议,但可通过在 Info.plist 中声明如上图所示的内容,倒退回不安全的网络请求,这样依然能让 App 访问指定 HTTP,甚至任意的 HTTP。

posted @ 2016-02-25 19:51  听风观雨阁  阅读(559)  评论(0编辑  收藏  举报