Search code examples
iosswiftplistnsurlrequest

App Transport Security blocks http request when it's allowed


Hi everyone. I have strange issue with App Transport Security on ios9 on share extension. Our project has 2 targets, ios project (based on phonegap) and native share extension. On both targets we do non https requests and on both target I have added

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

to .plist files, so ATS should be turned off. On application it works and I can do non https requests without problems, but on share extension it still blocks my requests **See screenshot here**

Somebody knows how can we fix it?


Solution

  • You should allow your specific domain first, like this.

    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSExceptionDomains</key>
        <dict>
            <key>api.domainname.com</key>
            <dict>
                <key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
                <true/>
            </dict>
            <key>dev.domainname.com</key>
            <dict>
                <key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
                <true/>
            </dict>
        </dict>
    </dict>