public static void OnPostprocessBuild(BuildTarget buildTarget, string path) { #if UNITY_IOS BuildTargetSettings_iOS current = Util.currentBuilder.iosSettings; if (buildTarget != BuildTarget.iOS || current == null) { return; } // Generate exportOptions.plist automatically. if (current.generateExportOptionPlist) { var plist = new PlistDocument(); plist.root.SetString("teamID", current.developerTeamId); plist.root.SetString("method", current.exportMethod); plist.root.SetBoolean("uploadBitcode", current.uploadBitcode); plist.root.SetBoolean("uploadSymbols", current.uploadSymbols); // Generate exportOptions.plist into build path. plist.WriteToFile(Path.Combine(path, "exportOptions.plist")); } // Support languages. string[] languages = current.languages.Split(';'); if (0 < languages.Length) { // Load Info.plist string infoPlistPath = Path.Combine(path, "Info.plist"); var plist = new PlistDocument(); plist.ReadFromFile(infoPlistPath); // Set default language. plist.root.SetString("CFBundleDevelopmentRegion", languages[0]); PlistElementArray bundleLocalizations = plist.root.values.ContainsKey("CFBundleLocalizations") ? plist.root.values["CFBundleLocalizations"].AsArray() : plist.root.CreateArray("CFBundleLocalizations"); // Add support language. foreach (var lang in current.languages.Split(';')) { if (bundleLocalizations.values.All(x => x.AsString() != lang)) { bundleLocalizations.AddString(lang); } } // Save Info.plist plist.WriteToFile(infoPlistPath); } // Modify XCode project. string projPath = PBXProject.GetPBXProjectPath(path); PBXProject proj = new PBXProject(); proj.ReadFromFile(projPath); string targetGuid = proj.TargetGuidByName(PBXProject.GetUnityTargetName()); // Modify build properties. proj.SetBuildProperty(targetGuid, "ENABLE_BITCODE", current.uploadBitcode ? "YES" : "NO"); if (!string.IsNullOrEmpty(current.developerTeamId)) { proj.SetBuildProperty(targetGuid, "DEVELOPMENT_TEAM", current.developerTeamId); } if (!current.automaticallySign && !string.IsNullOrEmpty(current.profileId)) { proj.SetBuildProperty(targetGuid, "PROVISIONING_PROFILE", current.profileId); } if (!current.automaticallySign && !string.IsNullOrEmpty(current.profileSpecifier)) { proj.SetBuildProperty(targetGuid, "PROVISIONING_PROFILE_SPECIFIER", current.profileSpecifier); } if (!current.automaticallySign && !string.IsNullOrEmpty(current.codeSignIdentity)) { proj.SetBuildProperty(targetGuid, "CODE_SIGN_IDENTITY", current.codeSignIdentity); } // Set entitlement file. if (!string.IsNullOrEmpty(current.entitlementsFile)) { string filename = Path.GetFileName(current.entitlementsFile); if (!proj.ContainsFileByProjectPath(filename)) { proj.AddFile("../" + current.entitlementsFile, filename); } proj.SetBuildProperty(targetGuid, "CODE_SIGN_ENTITLEMENTS", filename); } // Add frameworks. if (!string.IsNullOrEmpty(current.frameworks)) { foreach (var fw in current.frameworks.Split(';')) { proj.AddFrameworkToProject(targetGuid, fw, false); } } // Activate services. if (!string.IsNullOrEmpty(current.services) && !string.IsNullOrEmpty(current.developerTeamId)) { Regex reg = new Regex("(\\t*SystemCapabilities = {\\n)((.*{\\n.*\\n.*};\\n)+)"); string replaceText = string.Format("\nDevelopmentTeam = {0};\n$0{1}\n" , current.developerTeamId , current.services.Split(';').Select(x => x + " = {enabled = 1;};").Aggregate((a, b) => a + b) ); proj.ReadFromString(reg.Replace(proj.WriteToString(), replaceText)); } // Save XCode project. proj.WriteToFile(projPath); #endif }