Skip to content

Instantly share code, notes, and snippets.

@auycro
Created November 19, 2015 07:04
Show Gist options
  • Save auycro/8ae96405846b28e6fe15 to your computer and use it in GitHub Desktop.
Save auycro/8ae96405846b28e6fe15 to your computer and use it in GitHub Desktop.
Unity3D postprocess script c#
#if UNITY_IPHONE
using UnityEngine;
using UnityEditor;
using UnityEditor.Callbacks;
using System;
using System.Diagnostics;
using UnityEditor.iOS.Xcode;
using System.IO;
public class CustomPostprocessScript : MonoBehaviour
{
//IMPORTANT!!!
//100 is order , it means this one will execute after e.g 1 as default one is 1
//it means our script will run after all other scripts got run
[PostProcessBuild(100)]
public static void OnPostprocessBuild(BuildTarget target, string pathToBuildProject)
{
UpdateInfoPlist (pathToBuildProject);
string objCPath = Application.dataPath;
Process myCustomProcess = new Process();
myCustomProcess.StartInfo.FileName = "python";
myCustomProcess.StartInfo.Arguments = string.Format("Assets/Editor/post_process.py \"{0}\" \"{1}\"", pathToBuildProject, objCPath);
myCustomProcess.StartInfo.UseShellExecute = false;
myCustomProcess.StartInfo.RedirectStandardOutput = false;
myCustomProcess.Start();
myCustomProcess.WaitForExit();
}
private static void AddIOSAppTransportSecurity(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 ATS fix
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 ());
}
private static void AddSplitScreenOnIpad(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 LauchScreen
rootDict.SetString ("UILaunchStoryboardName","LaunchScreen");
//Add Orieantation
PlistElementArray UISupportedInterfaceOrientationsIpad = rootDict.CreateArray("UISupportedInterfaceOrientations~ipad");
UISupportedInterfaceOrientationsIpad.AddString ("UIInterfaceOrientationPortrait");
UISupportedInterfaceOrientationsIpad.AddString ("UIInterfaceOrientationPortraitUpsideDown");
UISupportedInterfaceOrientationsIpad.AddString ("UIInterfaceOrientationLandscapeLeft");
UISupportedInterfaceOrientationsIpad.AddString ("UIInterfaceOrientationLandscapeRight");
//WriteFile
File.WriteAllText (plistPath, plist.WriteToString ());
}
private static void UpdateInfoPlist(string path){
AddIOSAppTransportSecurity (path);
AddSplitScreenOnIpad (path);
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment