#if UNITY_IOS using System; using System.IO; using CCFramework.CrashReport.Editor; using UnityEditor; using UnityEditor.Callbacks; using UnityEngine; namespace Editor { public static class CrashPostProcessBuildIOS { private const string UnityFrameworkTarget = "target 'UnityFramework' do"; [PostProcessBuild(980)] public static void OnPostProcessBuild(BuildTarget target, string pathToBuiltProject) { if (target != BuildTarget.iOS) { return; } CrashReportBuglyProfileSettings settings = CrashReportBuildSettingsStore.GetLastBuildProfileSettings(); if (settings == null || !settings.enableIOSPod) { return; } EnsureBuglyPod(pathToBuiltProject, settings.iosPodVersion); } public static void EnsureBuglyPod(string pathToBuiltProject, string podVersion) { string podfilePath = Path.Combine(pathToBuiltProject, "Podfile"); string content = File.Exists(podfilePath) ? File.ReadAllText(podfilePath) : string.Empty; string normalizedVersion = string.IsNullOrWhiteSpace(podVersion) ? "~> 2.6" : podVersion.Trim(); string podLine = $" pod 'Bugly', '{normalizedVersion}'"; 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 依赖({normalizedVersion}),请在 Xcode 构建前执行 pod install。"); } } } #endif