Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • 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
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

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

3 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
1

Answer by dimitris_baud · Jan 28, 2020 at 10:54 AM

Thanks so much for posting the above. Below is the modern version of this script. Make sure you put it inside an Editor folder and it will run automatically on each build.

 using UnityEditor;
 using UnityEditor.Build;
 using System.IO;
 using UnityEditor.Build.Reporting;
 using UnityEditor.iOS.Xcode;
 
 // adds an ATS exception domain to the Info.plist
 public class InfoPlistUpdater : IPostprocessBuildWithReport
 {
     public int callbackOrder { get { return 0; } }
 
     public void OnPostprocessBuild(BuildReport report)
     {
         BuildTarget buildTarget = report.summary.platform;
         string pathToBuiltProject = report.summary.outputPath;
 
         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("your.domain.to.make.an.exception.for");
             domainDict.SetBoolean("NSExceptionAllowsInsecureHTTPLoads", true);
             domainDict.SetBoolean("NSIncludesSubdomains", true);
 
             // Write to file
             File.WriteAllText(plistPath, plist.WriteToString());
         }
     }
 }
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
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.

Follow this Question

Answers Answers and Comments

161 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

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 8 Answers

Crazy high RAM usage on IOS 0 Answers

WWW class doesn't work well. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges