Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Unity XcodeAPI Settings Sample
using System.IO;
using UnityEngine;
using UnityEditor;
using UnityEditor.iOS.Xcode;
using UnityEditor.Callbacks;
using System.Collections;
public class XcodeSettingsPostProcesser
[PostProcessBuildAttribute (0)]
public static void OnPostprocessBuild (BuildTarget buildTarget, string pathToBuiltProject)
// Stop processing if targe is NOT iOS
if (buildTarget != BuildTarget.iOS)
// Initialize PbxProject
var projectPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj";
PBXProject pbxProject = new PBXProject ();
pbxProject.ReadFromFile (projectPath);
string targetGuid = pbxProject.TargetGuidByName ("Unity-iPhone");
// Sample of adding build property
pbxProject.AddBuildProperty(targetGuid, "OTHER_LDFLAGS", "-all_load");
// Sample of setting build property
pbxProject.SetBuildProperty(targetGuid, "ENABLE_BITCODE", "NO");
// Sample of update build property
pbxProject.UpdateBuildProperty(targetGuid, "OTHER_LDFLAGS", new string[]{"-ObjC"}, new string[]{"-weak_framework"});
// Sample of adding REQUIRED framwrok
pbxProject.AddFrameworkToProject(targetGuid, "Security.framework", false);
// Sample of adding OPTIONAL framework
pbxProject.AddFrameworkToProject(targetGuid, "SafariServices.framework", true);
// Sample of setting compile flags
var guid = pbxProject.FindFileGuidByProjectPath("Classes/UI/");
var flags = pbxProject.GetCompileFlagsForFile(targetGuid, guid);
pbxProject.SetCompileFlagsForFile(targetGuid, guid, flags);
// Apply settings
File.WriteAllText (projectPath, pbxProject.WriteToString ());
// Samlpe of editing Info.plist
var plistPath = Path.Combine (pathToBuiltProject, "Info.plist");
var plist = new PlistDocument ();
plist.ReadFromFile (plistPath);
// Add string setting
plist.root.SetString ("hogehogeId", "dummyid");
// Add URL Scheme
var array = plist.root.CreateArray ("CFBundleURLTypes");
var urlDict = array.AddDict ();
urlDict.SetString ("CFBundleURLName", "hogehogeName");
var urlInnerArray = urlDict.CreateArray ("CFBundleURLSchemes");
urlInnerArray.AddString ("hogehogeValue");
// Apply editing settings to Info.plist
plist.WriteToFile (plistPath);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.