简体   繁体   English

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

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

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.我似乎无法将其添加到我的 info.plist 中。 There is no value it.没有它的价值。 I'm running XCode Version 7.0 beta (7A121l), and testing on iOS9.我正在运行 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,所以我不断收到“App Transport Security 已阻止明文 HTTP (http://) 资源加载,因为它不安全。可以通过您的应用程序配置临时异常Info.plist 文件”错误。

However, I don't seem to be able to configure it.但是,我似乎无法配置它。 Any ideas?有任何想法吗?

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 证书,这样就不会泄露隐私。

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>

在此处输入图片说明

That wasn't working for me, but this did the trick:这对我不起作用,但这确实有效:

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

Just to clarify ... You should always use httpS只是为了澄清......您应该始终使用 httpS

But you can bypass it adding the exception:但是您可以绕过它添加异常:

在此处输入图片说明

Xcode 8.2, iOS 10 Xcode 8.2,iOS 10

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

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.但是,开发人员仍然可以关闭 ATS 并允许他们的应用程序通过 HTTP 连接发送数据,如上述答案中所述。 At the end of 2016, Apple will make ATS mandatory for all developers who hope to submit their apps to the App Store. 2016 年底,Apple 将强制要求所有希望将其应用程序提交到 App Store 的开发者使用ATS link 关联

<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

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

To explain a bit more about ParaSara's answer: App Transport security will become 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.作为开发人员,如果您的网络代码无法使用 App Transport 安全性,并且您希望在修复任何问题之前继续其他开发,您可以关闭它。 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.一旦你知道你应该立即重新打开它。

The solution that you must use in the future is not to use http at all, unless you use a third party server that doesn't support https.以后必须使用的解决方案是完全不使用http,除非使用不支持https的第三方服务器。 If your own server doesn't support https, Apple will have a problem with that.如果您自己的服务器不支持 https,Apple 就会遇到问题。 Even with third party servers, I wouldn't bet that Apple accepts it.即使使用第三方服务器,我也不会打赌 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.修复您的代码,不要请求许可运行不安全的代码。

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/

In mac shell command line , use the following command:在 mac shell 命令行 中,使用以下命令:

plutil -insert NSAppTransportSecurity -xml "<array><string> hidden </string></array>" [location of your xcode project]/Info.plist 

The command will add all the necessary values into your plist file.该命令会将所有必要的值添加到您的 plist 文件中。

XCODE 8, Swift 3: You need to add a row: ** XCODE 8,Swift 3:您需要添加一行:**

"App transport Security Setting" “应用传输安全设置”

** in the info.plist inside information Property list. ** 在 info.plist 里面的信息属性列表中。

Xcode 9.2, Swift 4, this works for me. Xcode 9.2,Swift 4,这对我有用。

<key>App Transport Security Settings</key>
<dict>
    <key>Allow Arbitrary Loads</key>
    <true/>
</dict>

Open your info.plist file of your project with any editor of your preference, then add this code at the end of the file before the last使用您喜欢的任何编辑器打开项目的 info.plist 文件,然后将此代码添加到文件末尾的最后一个之前

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将NSExtension和UNNotificationExtensionCategory键添加到Info.plist? - How can I add the NSExtension & UNNotificationExtensionCategory keys to Info.plist? 如何在构建时将按目标UIAppFonts添加到共享的Info.plist文件中 - How can I add per-target UIAppFonts to a shared Info.plist file at build time 应用程序因Info.plist文件麦克风中缺少目的字符串而被拒绝,但我无法在info.plist中添加说明 - App got rejected for missing Purpose String in Info.plist File Microphone, but I can't add the description in info.plist Xcode:如何将密钥添加到生成的 Info.plist 文件中(或合并生成的和现有的 Info.plist)? - Xcode: How to add key into generated Info.plist file (or merge generated and existing Info.plist)? Flutter/iOS:如何在 NotificationServiceExtension Info.plist 文件中使用 pubspec.yaml 的 App 版本? - Flutter/iOS: How can I use pubspec.yaml's App version in my NotificationServiceExtension Info.plist file? 为什么要在 info.plist 文件中添加图标? - Why to add icons in info.plist file? 如何将元素添加到 info.plist 数组? - How do I add elements to an info.plist array? 如何将自定义条目添加到 iOS watchKit 扩展 info.plist 中? - How can I add custom entries into iOS watchKit extension info.plist? 如何在Xcode的info.plist中将我的产品名称重置为默认值 - How can I reset my Product Name to default in info.plist in Xcode 如何配置我的目标以在Xcode中使用特定的Info.plist? - How can I configure my target to use a specific Info.plist in Xcode?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM