Send data over HTTP in iOS Simulator
You cannot simply send data to a HTTP server in your iOS app. Apple enforces the use of HTTPS and TLS. Therefore, plain HTTP isn’t possible anymore. If you try this in your app to test a local HTTP server, the request will be blocked. In the log you can see this error message:
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.
Cannot start load of Task <F72AD5D0-B8F3-42F3-B959-8FCC1EECF38B>.<1> since it does not conform to ATS policy
Task <F72AD5D0-B8F3-42F3-B959-8FCC1EECF38B>.<1> finished with error – code: -1022
While it is very good that Apple enforces HTTPS, it also creates a small problem for app developers. Either you set up your development environment to support HTTPS and TLS. Or you do have a problem. This problem can be solved by disabling the enforcement of HTTPS for developers.
Add an entry in the Info.plist file of the project. Add an exception to the App Transport Security Settings.
At the bottom of the entries, click on the + icon and select App Transport Security Settings. After the entry is added, click on the + item that appears on the item to add an additional parameter: Allow Arbitrary Loads. This is a Boolean value, and to allow iOS to connect to a HTTP service without security, set its value to YES.
That’s it. Now you can access from your iOS Simulator your developer HTTP server.
0 Comments