ios 如何将 NSAppTransportSecurity 添加到我的 info.plist 文件中?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31216758/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 06:43:22  来源:igfitidea点击:

How can I add NSAppTransportSecurity to my info.plist file?

iosobjective-cxcodeios9

提问by chris P

https://developer.apple.com/videos/wwdc/2015/?id=711@5:55

https://developer.apple.com/videos/wwdc/2015/?id=711@5:55

I can't seem to be able to add this to my info.plist. There is no value it. I'm running XCode Version 7.0 beta (7A121l), and testing on iOS9.

我似乎无法将其添加到我的 info.plist 中。没有它的价值。我正在运行 XCode 7.0 测试版 (7A121l),并在 iOS9 上进行测试。

Because I can't specifically declare what URL's I want as seen in the video, I keep getting "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" errors.

因为我无法像视频中看到的那样具体声明我想要的 URL,所以我不断收到“应用程序传输安全已阻止明文 HTTP (http://) 资源加载,因为它不安全。可以通过您的应用程序配置临时异常Info.plist 文件”错误。

However, I don't seem to be able to configure it. Any ideas?

但是,我似乎无法配置它。有任何想法吗?

回答by Ashish

try With this --- worked for me in Xcode-beta 4 7.0

试试这个 --- 在 Xcode-beta 4 7.0 中为我工作

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>yourdomain.com</key>
        <dict>
            <!--Include to allow subdomains-->
            <key>NSIncludesSubdomains</key>
            <true/>
            <!--Include to allow HTTP requests-->
            <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
            <true/>
            <!--Include to specify minimum TLS version-->
            <key>NSTemporaryExceptionMinimumTLSVersion</key>
            <string>TLSv1.1</string>
        </dict>
    </dict>
</dict>

Also one more option, if you want to disable ATS you can use this :

还有一个选项,如果你想禁用 ATS,你可以使用这个:

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

But this is not recommended at all. The server should have the SSL certificates and so that there is no privacy leaks.

但这根本不推荐。服务器应该有 SSL 证书,这样就不会泄露隐私。

回答by Hiren Varu

You have to add just the NSAllowsArbitraryLoads key to YES in NSAppTransportSecurity dictionary in your info.plist file.

您必须在 info.plist 文件的 NSAppTransportSecurity 字典中将 NSAllowsArbitraryLoads 键添加到 YES 。

For example,

例如,

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

enter image description here

在此处输入图片说明

回答by Bobby

That wasn't working for me, but this did the trick:

这对我不起作用,但这确实有效:

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

回答by Manuel Pardo

Just to clarify ... You should always use httpS

只是为了澄清......您应该始终使用 httpS

But you can bypass it adding the exception:

但是您可以绕过它添加异常:

enter image description here

在此处输入图片说明

回答by Oleg Malovichko

Xcode 8.2, iOS 10

Xcode 8.2,iOS 10

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

回答by Paraneetharan Saravanaperumal

Update Answer (after wwdc 2016):

更新答案(在 wwdc 2016 之后):

IOS apps will require secure HTTPS connections by the end of 2016

App Transport Security, or ATS, is a feature that Apple introduced in iOS 9. When ATS is enabled, it forces an app to connect to web services over an HTTPS connection rather than non secure HTTP.

应用传输安全(ATS)是 Apple 在 iOS 9 中引入的一项功能。启用 ATS 后,它会强制应用通过 HTTPS 连接而不是非安全 HTTP 连接到 Web 服务。

However, developers can still switch ATS off and allow their apps to send data over an HTTP connection as mentioned in above answers. At the end of 2016, Apple will make ATS mandatoryfor all developers who hope to submit their apps to the App Store. link

但是,开发人员仍然可以关闭 ATS 并允许他们的应用程序通过上述答案中提到的 HTTP 连接发送数据。2016 年底,Apple 将强制要求所有希望将其应用程序提交到 App Store 的开发者使用ATS关联

回答by Santhosh Legent

<key>NSAppTransportSecurity</key>
    <dict>
        <key>NSExceptionDomains</key>
        <dict>
            <key>uservoice.com</key>
            <dict>
                <key>NSIncludesSubdomains</key>
                <true/>
                <key>NSExceptionRequiresForwardSecrecy</key>
                <false/>
            </dict>
        </dict>
    </dict>

回答by Subirdcom

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>com</key>
        <dict>
            <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
            <true/>
        </dict>
        <key>net</key>
        <dict>
            <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
            <true/>
        </dict>
        <key>org</key>
        <dict>
            <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
            <true/>
        </dict>
    </dict>
</dict>

This will allow to connect to .com .net .org

这将允许连接到 .com .net .org

回答by gnasher729

To explain a bit more about ParaSara's answer: App Transport security willbecome mandatory and trying to turn it off may get your app rejected.

详细解释一下 ParaSara 的回答:App Transport security成为强制性的,尝试关闭它可能会导致您的应用程序被拒绝。

As a developer, you can turn App Transport security off if your networking code doesn't work with it, and you want to continue other development before fixing any problems. Say in a team of five, four can continue working on other things while one fixes all the problems. You can also turn App Transport security off as a debugging tool if you have networking problems and you want to check if they are caused by App Transport security. As soon as you know you should turn it on again immediately.

作为开发人员,如果您的网络代码无法使用 App Transport 安全性,并且您希望在修复任何问题之前继续其他开发,您可以关闭它。假设在一个五人团队中,四人可以继续做其他事情,而一个人可以解决所有问题。如果您遇到网络问题并且想要检查它们是否由应用传输安全引起,您还可以将应用传输安全作为调试工具关闭。一旦你知道你应该立即重新打开它。

The solution that you mustuse in the future is not to use http at all, unless you use a third party server that doesn't support https. If your own server doesn't support https, Apple will have a problem with that. Even with third party servers, I wouldn't bet that Apple accepts it.

以后必须使用的解决方案是完全不使用http,除非使用不支持https的第三方服务器。如果您自己的服务器不支持 https,Apple 就会遇到问题。即使使用第三方服务器,我也不会打赌 Apple 会接受它。

Same with the various checks for server security. At some point Apple will only accept justifiable exceptions.

与服务器安全的各种检查相同。在某些时候,Apple 只会接受合理的例外情况。

But mostly, consider this: You are endangering the privacy of your customers. That's a big no-no in my book. Don't do that. Fix your code, don't ask for permission to run unsafe code.

但大多数情况下,请考虑这一点:您正在危及客户的隐私。这是我书中的一大禁忌。不要那样做。修复您的代码,不要请求许可运行不安全的代码。

回答by Kahng

One bad news for developers using NSAppTransportSecurity.

对于使用 NSAppTransportSecurity 的开发人员来说,一个坏消息。

UPDATE:
[Apple will require HTTPS connections for iOS apps by the end of 2016]

https://techcrunch.com/2016/06/14/apple-will-require-https-connections-for-ios-apps-by-the-end-of-2016/

https://techcrunch.com/2016/06/14/apple-will-require-https-connections-for-ios-apps-by-the-end-of-2016/