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

前端 未结 14 1298
野趣味
野趣味 2020-11-22 12:48

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.

相关标签:
14条回答
  • 2020-11-22 13:22

    try With this --- worked for me in 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 :

    <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.

    0 讨论(0)
  • 2020-11-22 13:25

    Xcode 9.2, Swift 4, this works for me.

    <key>App Transport Security Settings</key>
    <dict>
        <key>Allow Arbitrary Loads</key>
        <true/>
    </dict>
    
    0 讨论(0)
  • 2020-11-22 13:30

    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.

    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.

    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. 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.

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

    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.

    0 讨论(0)
  • 2020-11-22 13:33

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

    For example,

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

    0 讨论(0)
  • 2020-11-22 13:36

    Just to clarify ... You should always use httpS

    But you can bypass it adding the exception:

    0 讨论(0)
  • 2020-11-22 13:36

    One bad news for developers using 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/

    0 讨论(0)
提交回复
热议问题