NSAllowsArbitraryLoads not working

2019-02-08 14:23发布

I had a working app that downloads some info from an http domain. But after the Swift 2.0 and Xcode 7 update, my app can't connect to the server and download the json data, I get the "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." error.

I have tried putting this lines in my info.plist:

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

But I get the same error, it's not working. I always get nil data from the download methods. Any one has this same error? Thanks!

EDIT: Here is a picture from my info.plist file:

Info.plist file

10条回答
我想做一个坏孩纸
2楼-- · 2019-02-08 14:50

If you need to load a http:// resource only in web (UIWebView/WKWebView/SafariViewController) then the following should suffice.

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoadsInWebContent</key>
    <true/>
</dict>
查看更多
Evening l夕情丶
3楼-- · 2019-02-08 14:50

None of the previous solutions worked for me, I had the NSAllowsArbitraryLoads set to true, but still HTP wont work, after looking around I noticed that the info.plist file has NSExceptionDomains section, so I deleted it for testing and everything worked.

So it seems that having NSExceptionDomains cancels the NSAllowsArbitraryLoads, hope this is helpful.

查看更多
Melony?
4楼-- · 2019-02-08 14:55

Did you try to add your domain such as? You should add it into NSAppTransportSecurity dictionary.

<key>NSExceptionDomains</key>
        <dict>
            <key>abcde.com</key>
            <dict>
                <key>NSExceptionRequiresForwardSecrecy</key>
                <true/>
                <key>NSIncludesSubdomains</key>
                <true/>
                <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
                <true/>
            </dict>
        </dict>
查看更多
闹够了就滚
5楼-- · 2019-02-08 14:55

I had a similar issue and after a while I figured out that the info.plist file was corrupted. I can only advise to check the xml directly not only the plist editor in xcode.

查看更多
登录 后发表回答