Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift2.0 HTTP request not working [duplicate]

Tags:

ios

swift

xcode7

Hello Stackoverflow,

I keep getting this error after I moved my swift app onto Swift2.0:

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.
The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.

And I took a look at the following link https://forums.developer.apple.com/thread/5835

and added the following code to my info.plist

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

And it still doesn't work, anyone have an alternative solution?

like image 886
KPath001 Avatar asked Jul 27 '15 14:07

KPath001


1 Answers

Its not a Swift 2.0 issue its actually an iOS 9.0 issue where iOS 9.0 forces web traffic to go over https setting the below flag allows http traffic.

You have to set the NSAllowsArbitraryLoads key to YES under NSAppTransportSecurity dictionary in your .plist file. Hope this helps!

enter image description here

like image 183
User123335511231 Avatar answered Nov 02 '22 20:11

User123335511231