ioswatchkitapple-watchnsapptransportsecurity

Configuring App Transport Security for WatchKit (LaunchServicesError error 0.)


I am building a WatchKit app that talks to a non-HTTPS API, so I need to configure App Transport Security to allow for exception domains.

When I execute the NSURLRequest, I get the following error:

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.

So I've added this to my Info.plist:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>domain.com</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSExceptionAllowsInsecureHTTPLoads</key>
            <true/>
        </dict>
    </dict>
</dict>

But when I try to run in the Simulator, I get an Xcode error:

The operation couldn’t be completed. (LaunchServicesError error 0.)


Solution

  • The key to this is that you need to add the NSAppTransportSecurity keys to the Info.plist file for your Watch Extension, not your WatchKit App or iPhone App targets.