MiRiNMan MiRiNMan - 4 months ago 20
iOS Question

ios 9 and NSAppTransportSecurity

There is a problem with iOS 9 and work with the server.
I info.plist set:

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


When you run the application through Xcode, everything is fine. Work with the server takes place perfectly. But as soon as I stop the application and try to run it by simply clicking on the icon in the simulator. The network stops working. The same problem when I send the application to the Review in TestFlight. The application is installed, but the network stops working again.

Xcode 7.0 (7a220)
iOS 9.0

Answer

Are you sure it's not working? I tested it and everything is fine.

Possible actions:

Having a Debug mode enabled, build your app, run it from Xcode and make sure that you don't get an App Transport Security error:

App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure.

when launching it from Xcode using your simulator. Now find a DEVICE_CODE of the same very simulator

(Hint: it will be one of these ~/Library/Developer/CoreSimulator/Devices/. The easiest way to find this code from Xcode is to go Window->Devices)

and open with Console its log file:

~/Library/Logs/CoreSimulator/<DEVICE_CODE>/system.log

Clear the history (just in case you can launch your app from Xcode once again and make sure your output is getting into the log-file you opened, and that you still don't get App Transport Security error in there).

Now launch your app from the simulator and check if you have any errors related to App Transport Security in the log.

For me I don't have any if none of them I get when working from Xcode.

==================================

P.S.:

It's strongly recommended to not set an NSAllowsArbitraryLoads to true, you'd rather want to achieve the desired result with:

<key>NSAppTransportSecurity</key>
<dict>
  <key>NSExceptionDomains</key>
  <dict>
    <key>yourserver.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>