Wednesday, May 25, 2016

App Transport Security has blocked a cleartext HTTP XCode 7

In iOS 9.0 all unsecured HTTP traffic is disabled by Apple. But you can enable this traffic by disabling App Transport Security in info.plist.
Otherwise you will get error like Image 1.

Image 1: App Transport Security has blocked a cleartext HTTP error.

Let's see how can we disable this App Transport Security in XCode 7. First of all check the project target property list. Find this "App Transport Security Settings" property in there. But usually if you create a new project, you are not going to find this property there. (in Image 2)

Image 2: App Transport Security Settings is not the project target properties.
 You can add this property from Info.plist. Open this .plist file and there you can find "Information Property List". Select this header then you can see a plus sign (+). (Image 3a & Image 3b).

Image 3a: Information Property List of Info.plist
Image 3b: Information Property List with its header










If you click on this (+) button you can see a list of properties there (Image 4). To add new property in the info.plist, just need to select the property from this list. In Image 5 you can see a new property named "App Transport Security Settings" has been added in this plist from the property list.


Image 4 : Property List
Image 5 : App Transport Security Settings added in the info.plist

After adding this new property in the plist, you need to set value for "Allow Arbitrary Loads" under this property like Image 6a. By the default  it's value is NO. But change it to YES. (Image 6b).

Image 6a: Adding Allow Arbitrary Loads
under the security settings
Image 6b: Changing value of Allow Arbitrary Loads












Now if you open the project target, you can see this "App Transport Security Settings" property there. (Image 7) If you need to change the value of this property do it from project target . You do not have to go to info.plist.

Image 7: Project target after adding App Transport Security setting in info.plist
Run your project now. Ta-da the website is loading perfectly. (Image 8)

Image 8: Project is running perfectly

No comments:

Post a Comment