Created
October 2, 2021 15:21
-
-
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_
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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