#if UNITY_IOS using System.IO; using System.Linq; using System.Text.RegularExpressions; using UnityEditor; using UnityEditor.Callbacks; using UnityEditor.iOS.Xcode; namespace DiamondArrow.Platform.Editor { static class DiamondIosBuild { [PostProcessBuild(100)] static void Configure(BuildTarget target, string output) { if (target != BuildTarget.iOS) return; string projectPath = PBXProject.GetPBXProjectPath(output); var project = new PBXProject(); project.ReadFromFile(projectPath); var main = project.GetUnityMainTargetGuid(); project.AddFrameworkToProject(project.GetUnityFrameworkTargetGuid(), "GameKit.framework", false); project.WriteToFile(projectPath); var entitlements = project.GetBuildPropertyForAnyConfig(main, "CODE_SIGN_ENTITLEMENTS"); if (string.IsNullOrEmpty(entitlements)) entitlements = "Unity-iPhone.entitlements"; var capabilities = new ProjectCapabilityManager(projectPath, entitlements, null, main); capabilities.AddGameCenter(); capabilities.WriteToFile(); string plistPath = Path.Combine(output, "Info.plist"); var plist = new PlistDocument(); plist.ReadFromFile(plistPath); plist.root.SetString("GADApplicationIdentifier", "ca-app-pub-8449397879714583~6362286720"); var networks = plist.root.values.TryGetValue("SKAdNetworkItems", out var items) ? items.AsArray() : plist.root.CreateArray("SKAdNetworkItems"); const string google = "cstr6suwn9.skadnetwork"; if (!networks.values.Any(item => item.AsDict().values.TryGetValue("SKAdNetworkIdentifier", out var id) && id.AsString() == google)) networks.AddDict().SetString("SKAdNetworkIdentifier", google); plist.WriteToFile(plistPath); } // Older Xcode postprocessors can discard a Swift product's PBXBuildFile while // retaining the package dependency that EDM4U added to UnityFramework. [PostProcessBuild(1001)] static void LinkAdMobSwiftProduct(BuildTarget target, string output) { if (target != BuildTarget.iOS) return; var path = PBXProject.GetPBXProjectPath(output); var project = new PBXProject(); project.ReadFromFile(path); var framework = project.GetUnityFrameworkTargetGuid(); var text = project.WriteToString(); var targetBlock = Regex.Match(text, @"(?ms)^\t\t" + framework + @" /\* UnityFramework \*/ = \{.*?^\t\t\};"); var product = Regex.Match(targetBlock.Value, @"\b([0-9A-Fa-f]{24}) /\* GoogleMobileAds \*/,"); if (!product.Success) return; // CocoaPods integration has no Swift product. var guid = product.Groups[1].Value; if (text.Contains("productRef = " + guid)) return; // Add the existing product to this phase. Unity's public API for an // existing GUID writes fileRef, whereas Xcode requires productRef here. project.AddFileToBuildSection(framework, project.GetFrameworksBuildPhaseByTarget(framework), guid); var linked = project.WriteToString().Replace("fileRef = " + guid, "productRef = " + guid); File.WriteAllText(path, linked); } } } #endif