Skip to content

Instantly share code, notes, and snippets.

@auycro
Last active October 29, 2021 11:40
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save auycro/c671c5ae830588e89f70 to your computer and use it in GitHub Desktop.
Save auycro/c671c5ae830588e89f70 to your computer and use it in GitHub Desktop.
Unity update info.plist
//Copyright (c) 2015 Gumpanat Keardkeawfa
//Licensed under the MIT license
using System.IO;
using UnityEngine;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.iOS.Xcode;
public static class XCodePostProcess
{
[PostProcessBuild(100)]
public static void OnPostprocessBuild(BuildTarget target, string pathToBuildProject) {
if (target.ToString() == "iOS" || target.ToString() == "iPhone") {
UpdateInfoPlist(pathToBuildProject);
}
}
private static void UpdateInfoPlist(string path) {
//Get Plist
string plistPath = Path.Combine(path, "Info.plist");
PlistDocument plist = new PlistDocument();
plist.ReadFromString (File.ReadAllText (plistPath));
//Get Root
PlistElementDict rootDict = plist.root;
//Add Necessary Things
PlistElementArray LSApplicationQueriesSchemes = rootDict.CreateArray("LSApplicationQueriesSchemes");
LSApplicationQueriesSchemes.AddString ("fb");
LSApplicationQueriesSchemes.AddString ("instagram");
LSApplicationQueriesSchemes.AddString ("tumblr");
LSApplicationQueriesSchemes.AddString ("twitter");
LSApplicationQueriesSchemes.AddString ("twitter");
LSApplicationQueriesSchemes.AddString ("fbapi");
LSApplicationQueriesSchemes.AddString ("fbapi20130410");
LSApplicationQueriesSchemes.AddString ("fbapi20130702");
LSApplicationQueriesSchemes.AddString ("fbapi20131010");
LSApplicationQueriesSchemes.AddString ("fbapi20131219");
LSApplicationQueriesSchemes.AddString ("fbapi20140410");
LSApplicationQueriesSchemes.AddString ("fbapi20140116");
LSApplicationQueriesSchemes.AddString ("fbapi20150313");
LSApplicationQueriesSchemes.AddString ("fbapi20150629");
LSApplicationQueriesSchemes.AddString ("fbauth");
LSApplicationQueriesSchemes.AddString ("fbauth2");
LSApplicationQueriesSchemes.AddString ("fb-messenger-api20140430");
PlistElementDict NSAppTransportSecurity = rootDict.CreateDict("NSAppTransportSecurity");
NSAppTransportSecurity.SetBoolean("NSAllowsArbitraryLoads",true);
PlistElementDict NSExceptionDomains = NSAppTransportSecurity.CreateDict("NSExceptionDomains");
PlistElementDict url1 = NSExceptionDomains.CreateDict ("akamaihd.net");
url1.SetBoolean ("NSIncludesSubdomains",true);
url1.SetBoolean ("NSThirdPartyExceptionRequiresForwardSecrecy", false);
PlistElementDict url2 = NSExceptionDomains.CreateDict ("facebook.com");
url2.SetBoolean ("NSIncludesSubdomains",true);
url2.SetBoolean ("NSThirdPartyExceptionRequiresForwardSecrecy", false);
PlistElementDict url3 = NSExceptionDomains.CreateDict ("fbcdn.net");
url3.SetBoolean ("NSIncludesSubdomains",true);
url3.SetBoolean ("NSThirdPartyExceptionRequiresForwardSecrecy", false);
PlistElementDict url4 = NSExceptionDomains.CreateDict ("localhost");
url4.SetBoolean ("NSExceptionAllowsInsecureHTTPLoads",true);
//WriteFile
File.WriteAllText (plistPath, plist.WriteToString ());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment