NSAppTransportSecurity UIWebView问题 [英] NSAppTransportSecurity UIWebView issue

查看:96
本文介绍了NSAppTransportSecurity UIWebView问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的info.plist文件中有以下几行:

I have these lines in my info.plist file:

<key>NSAppTransportSecurity</key>
    <dict>
        <key>NSExceptionDomains</key>
        <dict>
            <key>mysebserver.com</key>
            <dict>
                <key>NSIncludesSubdomains</key>
                <true/>
                <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
                <true/>
                <key>NSTemporaryExceptionMinimumTLSVersion</key>
                <string>TLSv1.1</string>
            </dict>
        </dict>
    </dict>

因此它非常适合我的API调用.

So it works perfect with my API calls.

在我的视图控制器中,我有UIWebView试图显示Web内容:

In my view controller I have UIWebView that tries to display web content:

NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:self.webSiteUrlSting] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:30];

[self.theWebView loadRequest:request];

在iOS7和iOS8上运行良好,但在iOS9上,调用UIWebView委托- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error后显示错误:

on iOS7 and iOS8 it works great, but on iOS9 it shows an error after invocation UIWebView delegate - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error:

App Transport Security已阻止明文HTTP(http://)资源 加载,因为它是不安全的.临时异常可以通过配置 您应用的Info.plist文件.

App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.

委托方法包含如下所示的错误实例:

The delegate method contain error instance that looks like this:

Error Domain = NSURLErrorDomain代码= -1022资源不能为 已加载,因为应用程序传输安全性"策略要求使用 安全连接." UserInfo = {NSUnderlyingError = 0x7fbaa253ba20 {Error Domain = kCFErrorDomainCFNetwork代码= -1022资源不能为 已加载,因为应用程序传输安全性"策略要求使用 安全连接." UserInfo = {NSErrorFailingURLStringKey = requestedwebsite.com, NSLocalizedDescription =无法加载资源,因为 App Transport Security策略要求使用安全 联系., NSErrorFailingURLKey = requestedwebsite.com}}, NSErrorFailingURLStringKey = requestedwebsite.com, NSErrorFailingURLKey = requestedwebsite.com, NSLocalizedDescription =无法加载资源,因为 App Transport Security策略要求使用安全 连接.}

Error Domain=NSURLErrorDomain Code=-1022 "The resource could not be loaded because the App Transport Security policy requires the use of a secure connection." UserInfo={NSUnderlyingError=0x7fbaa253ba20 {Error Domain=kCFErrorDomainCFNetwork Code=-1022 "The resource could not be loaded because the App Transport Security policy requires the use of a secure connection." UserInfo={NSErrorFailingURLStringKey=requestedwebsite.com, NSLocalizedDescription=The resource could not be loaded because the App Transport Security policy requires the use of a secure connection., NSErrorFailingURLKey=requestedwebsite.com}}, NSErrorFailingURLStringKey=requestedwebsite.com, NSErrorFailingURLKey=requestedwebsite.com, NSLocalizedDescription=The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.}

我的问题是如何保持我的API请求正常工作,以及如何使UIWebView也正常工作.

My question is how to keep my API requests work and make UIWebView work as well.

推荐答案

在您的NSAppTransportSecurity字典中添加此异常:

Add this exception in your NSAppTransportSecurity dict:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

这篇关于NSAppTransportSecurity UIWebView问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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