using UnityEditor; using UnityEngine; using UnityEditor.Callbacks; using System.IO; using System.Collections; using System.Collections.Generic; using ChillyRoom.UnityEditor.iOS.Xcode; public class NewBehaviourScript { [PostProcessBuild(100)] public static void OnPostprocessBuild(BuildTarget buildTarget, string buildPath) { if (buildTarget != BuildTarget.iOS) { return; } string projectPath = PBXProject.GetPBXProjectPath(buildPath); PBXProject project = new PBXProject(); project.ReadFromFile(projectPath); //关闭BitCode string target = project.TargetGuidByName("Unity-iPhone"); project.SetBuildProperty(target, "ENABLE_BITCODE", "NO"); //添加引用库 string targetGuid = project.TargetGuidByName("Unity-iPhone"); project.AddFrameworkToProject(targetGuid, "libc++.tbd", false); project.AddFrameworkToProject(targetGuid, "libz.tbd", false); project.AddFrameworkToProject(targetGuid, "SystemConfiguration.framework", false); project.AddFrameworkToProject(targetGuid, "CoreTelephony.framework", false); project.AddFrameworkToProject(targetGuid, "QuartzCore.framework", false); project.AddFrameworkToProject(targetGuid, "CoreText.framework", false); project.AddFrameworkToProject(targetGuid, "CoreGraphics.framework", false); project.AddFrameworkToProject(targetGuid, "UIKit.framework", false); project.AddFrameworkToProject(targetGuid, "Foundation.framework", false); project.AddFrameworkToProject(targetGuid, "CFNetwork.framework", false); project.AddFrameworkToProject(targetGuid, "CoreMotion.framework", false); project.AddFrameworkToProject(targetGuid, "AlipaySDK.framework", false); project.AddFrameworkToProject(targetGuid, "Security.framework", false); //App名称本地化 string plistPath = Path.Combine(buildPath, "Info.plist"); PlistDocument plist = new PlistDocument(); plist.ReadFromFile(plistPath); plist.root.SetString("Bundle display name", "${CFBundleDisplayName }"); var infoDirs = Directory.GetDirectories(Application.dataPath + "/AppleDependency/"); for (var i = 0; i < infoDirs.Length; ++i) { var files = Directory.GetFiles(infoDirs[i], "*.strings"); project.AddLocalization(files[0], "InfoPlist.strings", "InfoPlist.strings"); } //修改UnityAppController.mm string scriptPath = buildPath + "/Classes/UnityAppController.mm"; //添加URLScheme PlistElementArray urlArray = plist.root.CreateArray("CFBundleURLTypes"); PlistElementDict urlDict = urlArray.AddDict(); urlDict.SetString("CFBundleURLName", "TestName"); PlistElementArray urlInnerArray = urlDict.CreateArray("TestScheme"); urlInnerArray.AddString("TestValue"); //保存Plist plist.WriteToFile(plistPath); //保存PBXProject File.WriteAllText(projectPath, project.WriteToString()); } }