Skip to content

Instantly share code, notes, and snippets.

@vsigno
Created October 2, 2021 15:21
Show Gist options
  • Save vsigno/6148efa00e949f35ba5e7df81b2cf2ed to your computer and use it in GitHub Desktop.
Save vsigno/6148efa00e949f35ba5e7df81b2cf2ed to your computer and use it in GitHub Desktop.
C# Script to fix iOS permission when a Unity iOS Project is built on Windows. NB: Save the script in a new (if not existing) _Editor_ folder under _Assets_
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
#if UNITY_IOS || UNITY_IPHONE
using UnityEditor.iOS.Xcode;
#endif
using UnityEditor.Callbacks;
 
public static class iOSBuildPermissionFix
{
#if UNITY_EDITOR && (UNITY_IOS || UNITY_IPHONE)
    [PostProcessBuild(0)]
    public static void OnPostProcessBuild(BuildTarget buildTarget, string path)
    {
        if (buildTarget != BuildTarget.iOS)
        {
            return;
        }
 
        string projectPath = PBXProject.GetPBXProjectPath(path); ;
        PBXProject pbxProject = new PBXProject();
        pbxProject.ReadFromFile(projectPath);
 
        string targetGUID = pbxProject.GetUnityFrameworkTargetGuid();
 
        string shellPath = "/bin/sh";
        int index = 0;
        string name = "Fix Permissions in Windows Generated XcodeProject";
        string shellScript = "chmod a+x \"$PROJECT_DIR/MapFileParser.sh\"";
        pbxProject.InsertShellScriptBuildPhase(index, targetGUID, name, shellPath, shellScript);
        pbxProject.WriteToFile(projectPath);
 
        Debug.Log("<color=green>iOS Build Permission Fix</color> Applied to XcodeProject");
    }
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment