• Unity
  • Services
  • Made with Unity
  • Learn
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Forums
  • Answers
  • Feedback
  • Issue Tracker
  • Blog
  • Evangelists
  • User Groups

Navigation

  • Home
  • Unity
  • Industries
  • Made with Unity
  • Learn
  • Community
    • Forums
    • Answers
    • Feedback
    • Issue Tracker
    • Blog
    • Evangelists
    • User Groups
  • Get Unity
  • Asset Store

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Treegemmer · Nov 12, 2017 at 07:08 AM · iosimportwwwxcodehttp

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

I need to access a HTTP request through amazonaws.com, which works on android but Xcode gives this error above "App Transport Security has blocked..."
I found that I need to modify the info.plist to add exceptions: https://stackoverflow.com/questions/31254725/transport-security-has-blocked-a-cleartext-http

And I found an example here of how it's possible to modify info.plist with post-process build: https://forum.unity.com/threads/how-can-you-add-items-to-the-xcode-project-targets-info-plist-using-the-xcodeapi.330574/

But can't find any examples of how I would construct the nested Dictionaries to make it happen.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Treegemmer · Nov 12, 2017 at 07:11 AM

I couldn't find any documentation on how to use these methods, but did get it working through trial and error.

Hopefully this will help others in the future.

 public class AllowHTTPSupportCodes : MonoBehaviour 
 {
     [PostProcessBuild]
     public static void OnPostprocessBuild(BuildTarget buildTarget, string pathToBuiltProject) 
     {
         if (buildTarget == BuildTarget.iOS) {
 
             // Get plist
             string plistPath = pathToBuiltProject + "/Info.plist";
             PlistDocument plist = new PlistDocument();
             plist.ReadFromString(File.ReadAllText(plistPath));
 
             PlistElementDict allowsDict = plist.root.CreateDict("NSAppTransportSecurity");
 
             allowsDict.SetBoolean("NSAllowsArbitraryLoads", true);
 
             PlistElementDict exceptionsDict = allowsDict.CreateDict("NSExceptionDomains");
 
             PlistElementDict domainDict = exceptionsDict.CreateDict("amazonaws.com");
 
             domainDict.SetBoolean("NSExceptionAllowsInsecureHTTPLoads", true);
             domainDict.SetBoolean("NSIncludesSubdomains", true);
 
             // Write to file
             File.WriteAllText(plistPath, plist.WriteToString());
         }
     }
 }



Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image fugogugo · Aug 10, 2018 at 07:54 AM 0
Share

Thank you so much!

I've been fiddling for days trying to figure out why my app cannot connect to server. Turns out unsecured HTTP is the culprit. this piece of code solved my problem :D

avatar image
0

Answer by Bunny83 · Aug 10, 2018 at 09:09 AM

Apple requires your App to use https and does not allow http connections for quite some time now. HTTPS is the recommended protocol in general when you deal with HTTP.. Disabling https is generally not recommended. If your server does not support https you may want to change the server. Disabling https should only be use in rare cases.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

165 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity iOS - Wont compile in Xcode 2 Answers

expected unqualified id on libiconv.2.tbd 0 Answers

xcode - linker command failed with exit code 1 7 Answers

Plugin dependencies and compiler flags 1 Answer

Open iOS Media Browser and import selected image as texture 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges