2026-06-12 16:42:45 +08:00
|
|
|
#if UNITY_IOS
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
2026-06-14 18:18:05 +08:00
|
|
|
using CCFramework.CrashReport.Editor;
|
2026-06-12 16:42:45 +08:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-14 18:18:05 +08:00
|
|
|
CrashReportBuglyProfileSettings settings = CrashReportBuildSettingsStore.GetLastBuildProfileSettings();
|
|
|
|
|
if (settings == null || !settings.enableIOSPod)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EnsureBuglyPod(pathToBuiltProject, settings.iosPodVersion);
|
2026-06-12 16:42:45 +08:00
|
|
|
}
|
|
|
|
|
|
2026-06-14 18:18:05 +08:00
|
|
|
public static void EnsureBuglyPod(string pathToBuiltProject, string podVersion)
|
2026-06-12 16:42:45 +08:00
|
|
|
{
|
|
|
|
|
string podfilePath = Path.Combine(pathToBuiltProject, "Podfile");
|
|
|
|
|
string content = File.Exists(podfilePath) ? File.ReadAllText(podfilePath) : string.Empty;
|
2026-06-14 18:18:05 +08:00
|
|
|
string normalizedVersion = string.IsNullOrWhiteSpace(podVersion) ? "~> 2.6" : podVersion.Trim();
|
|
|
|
|
string podLine = $" pod 'Bugly', '{normalizedVersion}'";
|
2026-06-12 16:42:45 +08:00
|
|
|
|
|
|
|
|
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 +
|
2026-06-14 18:18:05 +08:00
|
|
|
podLine + Environment.NewLine +
|
2026-06-12 16:42:45 +08:00
|
|
|
"end" + Environment.NewLine);
|
|
|
|
|
}
|
|
|
|
|
else if (content.Contains(UnityFrameworkTarget))
|
|
|
|
|
{
|
2026-06-14 18:18:05 +08:00
|
|
|
content = content.Replace(UnityFrameworkTarget, UnityFrameworkTarget + Environment.NewLine + podLine);
|
2026-06-12 16:42:45 +08:00
|
|
|
File.WriteAllText(podfilePath, content);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
File.AppendAllText(podfilePath,
|
|
|
|
|
Environment.NewLine +
|
|
|
|
|
UnityFrameworkTarget + Environment.NewLine +
|
2026-06-14 18:18:05 +08:00
|
|
|
podLine + Environment.NewLine +
|
2026-06-12 16:42:45 +08:00
|
|
|
"end" + Environment.NewLine);
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-14 18:18:05 +08:00
|
|
|
Debug.Log($"CrashReport iOS 已写入 Bugly CocoaPods 依赖({normalizedVersion}),请在 Xcode 构建前执行 pod install。");
|
2026-06-12 16:42:45 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|