Skip to content

Instantly share code, notes, and snippets.

@mattbajorek
Last active April 13, 2020 00:11
Show Gist options
  • Save mattbajorek/b6bc153905124a45119903354f3fd52e to your computer and use it in GitHub Desktop.
Save mattbajorek/b6bc153905124a45119903354f3fd52e to your computer and use it in GitHub Desktop.
iOS Editor BuildPostProcessor
using UnityEngine;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.iOS.Xcode;
using System.IO;
using System.Linq;
public class BuildPostProcessor
{
[PostProcessBuild]
public static void OnPostProcessBuild(BuildTarget target, string path)
{
if (target == BuildTarget.iOS)
{
// Get project into C#
var projectPath = PBXProject.GetPBXProjectPath(path);
var project = new PBXProject();
project.ReadFromFile(projectPath);
// Get targetGUID
var targetName = PBXProject.GetUnityTargetName();
var targetGUID = project.TargetGuidByName(targetName);
// Built in Frameworks
project.AddFrameworkToProject(targetGUID, "Foundation.framework", false);
Debug.Log("Added iOS frameworks to project");
...
// Add `-ObjC` to "Other Linker Flags".
project.AddBuildProperty(targetGUID, "OTHER_LDFLAGS", "-ObjC");
// Overwrite
project.WriteToFile(projectPath);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment