ios 9 and NSAppTransportSecurity

这一生的挚爱 提交于 2019-12-03 08:29:41

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>

It should be done like this, you need to add in your Plist the following records Apple Documentation

It is lazy so your frameworks have access to Internet

NSAppTransportSecurity <- Type Dictionary

NSAllowsArbitraryLoads <- Type Boolean Value YES

Its very simple, just follow the below steps:

  1. App Transport security settings.
  2. Allow Arbitrary loads.
  3. Exception domains and the domain/host reference.

Note: This issue happens because your project settings does not allow by default any cross site scripting references. Hence, it blocks any service calls that goes outside of your app.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!