using UnityEngine; using UnityEditor; using UnityEditor.Callbacks; using UnityEditor.iOS.Xcode; using System.Collections.Generic; using System.IO;
public class ModifyXcodeProj { [PostProcessBuild(200)] public static void OnPostprocessBuild(BuildTarget buildTarget, string path) { if (buildTarget == BuildTarget.iOS) if (!OnPostprocessBuildForiOS(path)) EditorApplication.Exit(1); }
private static bool OnPostprocessBuildForiOS(string path) { string projPath = PBXProject.GetPBXProjectPath(path); PBXProject proj = new PBXProject(); proj.ReadFromFile(projPath);
string targetName = "Unity-iPhone"; string targetGuid = proj.TargetGuidByName(targetName); if (targetGuid == null) { Debug.LogError("Cannot find " + targetName); return false; }
List<string> flags = new List<string>() {"-fno-objc-arc"}; foreach (string filePath in new string[]{"Facebook/FbUnityInterface.mm"}) { string fileGuid = proj.FindFileGuidByProjectPath(filePath); if (fileGuid == null) { Debug.LogError("Cannot find " + filePath); return false; } proj.SetCompileFlagsForFile(targetGuid, fileGuid, flags); }
foreach (string framework in new string[] {"StoreKit.framework", "CoreTelephony.framework"}) { proj.AddFrameworkToProject(targetGuid, framework, false); }
File.WriteAllText(projPath, proj.WriteToString());
return true; } }
|