#if UNITY_IOS using System; using System.IO; using UnityEditor; using UnityEditor.Callbacks; using UnityEngine; namespace Editor { public static class CrashPostProcessBuildIOS { private const string PodLine = " pod 'Bugly', '~> 2.6'"; private const string UnityFrameworkTarget = "target 'UnityFramework' do"; [PostProcessBuild(980)] public static void OnPostProcessBuild(BuildTarget target, string pathToBuiltProject) { if (target != BuildTarget.iOS) { return; } EnsureBuglyPod(pathToBuiltProject); } private static void EnsureBuglyPod(string pathToBuiltProject) { string podfilePath = Path.Combine(pathToBuiltProject, "Podfile"); string content = File.Exists(podfilePath) ? File.ReadAllText(podfilePath) : string.Empty; if (content.Contains("pod 'Bugly'") || content.Contains("pod \"Bugly\"")) { return; } if (string.IsNullOrWhiteSpace(content)) { File.WriteAllText(podfilePath, "platform :ios, '9.0'" + Environment.NewLine + Environment.NewLine + UnityFrameworkTarget + Environment.NewLine + PodLine + Environment.NewLine + "end" + Environment.NewLine); } else if (content.Contains(UnityFrameworkTarget)) { content = content.Replace(UnityFrameworkTarget, UnityFrameworkTarget + Environment.NewLine + PodLine); File.WriteAllText(podfilePath, content); } else { File.AppendAllText(podfilePath, Environment.NewLine + UnityFrameworkTarget + Environment.NewLine + PodLine + Environment.NewLine + "end" + Environment.NewLine); } Debug.Log("CrashReport iOS 已写入 Bugly CocoaPods 依赖,请在 Xcode 构建前执行 pod install。"); } } } #endif