1. 添加位置权限请求逻辑适配iOS 14+ NEHotspotNetwork要求 2. 新增NetworkExtension框架依赖并更新Xcode项目配置 3. 修复构建脚本中的日志标识与应用名大小写问题 4. 更新启动图标配置与iOS项目设置 5. 优化WiFi SSID获取的兼容逻辑与日志输出
93 lines
2.9 KiB
C#
93 lines
2.9 KiB
C#
using UnityEditor;
|
|
using UnityEditor.Callbacks;
|
|
using UnityEditor.iOS.Xcode;
|
|
using System.IO;
|
|
using System.Text.RegularExpressions;
|
|
using UnityEngine;
|
|
|
|
public class iOSFixDuplicateShellScript
|
|
{
|
|
[PostProcessBuild(999)]
|
|
public static void OnPostProcessBuild(BuildTarget target, string pathToBuiltProject)
|
|
{
|
|
if (target != BuildTarget.iOS) return;
|
|
|
|
FixDuplicateShellScript(pathToBuiltProject);
|
|
FixPodfile(pathToBuiltProject);
|
|
AddNetworkExtensionFramework(pathToBuiltProject);
|
|
}
|
|
|
|
private static void FixDuplicateShellScript(string pathToBuiltProject)
|
|
{
|
|
string projPath = Path.Combine(pathToBuiltProject, "Unity-iPhone.xcodeproj/project.pbxproj");
|
|
if (!File.Exists(projPath))
|
|
{
|
|
Debug.LogWarning("[PostProcess] pbxproj not found: " + projPath);
|
|
return;
|
|
}
|
|
|
|
string content = File.ReadAllText(projPath);
|
|
|
|
string pattern = @"(\t+([A-F0-9]+) /\* ShellScript \*/,)\r?\n\t+\2 /\* ShellScript \*,/";
|
|
string newContent = Regex.Replace(content, pattern, "$1");
|
|
|
|
if (newContent != content)
|
|
{
|
|
File.WriteAllText(projPath, newContent);
|
|
Debug.Log("[PostProcess] Removed duplicate ShellScript from GameAssembly target");
|
|
}
|
|
|
|
// 修复光子矩阵 app 大小写
|
|
newContent = newContent.Replace("photonmatrix.app", "PhotonMatrix.app");
|
|
|
|
File.WriteAllText(projPath, newContent);
|
|
}
|
|
|
|
private static void FixPodfile(string pathToBuiltProject)
|
|
{
|
|
string podfilePath = Path.Combine(pathToBuiltProject, "Podfile");
|
|
if (!File.Exists(podfilePath))
|
|
{
|
|
Debug.LogWarning("[PostProcess] Podfile not found");
|
|
return;
|
|
}
|
|
|
|
string content = File.ReadAllText(podfilePath);
|
|
bool modified = false;
|
|
|
|
if (content.Contains("Firebase/Analytics"))
|
|
{
|
|
content = Regex.Replace(content, @"\s*pod\s+'Firebase/Analytics'[^\n]*\n?", "\n");
|
|
modified = true;
|
|
}
|
|
|
|
if (content.Contains("12.4.0"))
|
|
{
|
|
content = content.Replace("12.4.0", "12.14.0");
|
|
modified = true;
|
|
}
|
|
|
|
if (modified)
|
|
{
|
|
File.WriteAllText(podfilePath, content);
|
|
Debug.Log("[PostProcess] Cleaned up Podfile");
|
|
}
|
|
}
|
|
|
|
private static void AddNetworkExtensionFramework(string pathToBuiltProject)
|
|
{
|
|
string projPath = PBXProject.GetPBXProjectPath(pathToBuiltProject);
|
|
PBXProject proj = new PBXProject();
|
|
proj.ReadFromString(File.ReadAllText(projPath));
|
|
|
|
string unityFrameworkGuid = proj.GetUnityFrameworkTargetGuid();
|
|
bool added = proj.AddFrameworkToProject(unityFrameworkGuid, "NetworkExtension.framework", false);
|
|
|
|
if (added)
|
|
{
|
|
File.WriteAllText(projPath, proj.WriteToString());
|
|
Debug.Log("[PostProcess] Added NetworkExtension.framework");
|
|
}
|
|
}
|
|
}
|