Transport security has blocked a cleartext HTTP

2018-12-30 23:27发布

What setting do I need to put in my info.plist to enable HTTP mode as per the following error message?

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.

Xcode

Assume that my domain is example.com.

23条回答
千与千寻千般痛.
2楼-- · 2018-12-31 00:01

It may be worth mentioning how to get there...

Info.plist is one of the files below the Main.storyboard or viewController.swift.

When you click on it the first time, it usually is in a table format, so right click the file and 'open as' Source code and then add the code below towards the end, i.e.:

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

Copy paste the code just above

 "</dict>
</plist>"

which is at the end.

查看更多
与风俱净
3楼-- · 2018-12-31 00:03

Use:

PList Screenshot to understand better

Add a new item, NSAppTransportSecurity, in the plist file with type Dictionary, then add sub item NSAllowsArbitraryLoads in dictionary of type Boolean, and set bool value YES. This works for me.

查看更多
君临天下
4楼-- · 2018-12-31 00:04

Here are the settings visually:

visual settings for NSAllowsArbitraryLoads in info.plist via Xcode GUI

查看更多
萌妹纸的霸气范
5楼-- · 2018-12-31 00:05

If you are using Xcode 8.0 and Swift 3.0 or Swift 2.2 or even Objective C:

Enter image description here

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
    <key>NSExceptionDomains</key>
    <dict>
        <key>example.com</key>
        <dict>
            <key>NSExceptionAllowsInsecureHTTPLoads</key>
            <true/>
            <key>NSIncludesSubdomains</key>
            <true/>
        </dict>
    </dict>
</dict>
查看更多
萌妹纸的霸气范
6楼-- · 2018-12-31 00:06

Apple Document 1

Apple Document 2

There are two solutions for this :

Solutions 1 :

  1. In Info.plist file add a dictionary with key 'NSAppTransportSecurity'
  2. Add another element inside dictionary with key 'Allow Arbitrary Loads'

Plist structure should appear as shown in below image.

Solution 1

Solution 2 :

  1. In Info.plist file add a dictionary with key 'NSAppTransportSecurity'
  2. Add another element inside dictionary with key 'NSExceptionDomains'
  3. Add element with key 'MyDomainName.com' of type NSDictionary
  4. Add element with key 'NSIncludesSubdomains' of type Boolean and value set as YES
  5. Add element with key 'NSTemporaryExceptionAllowsInsecureHTTPLoads' of type Boolean and value set as YES

Plist structure should appear as shown in below image.

Solution 2

Solution 2 is preferred since it allows only selected domain whereas solution 1 allows all insecure HTTP connections.

查看更多
梦寄多情
7楼-- · 2018-12-31 00:06

Transport security is available on iOS 9.0 or later. You may have this warning when trying to call a WS inside your application:

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

Adding the following to your Info.plist will disable ATS:

<key>NSAppTransportSecurity</key>
<dict>
     <key>NSAllowsArbitraryLoads</key><true/>
</dict>
查看更多
登录 后发表回答