81 lines
2.8 KiB
C#
81 lines
2.8 KiB
C#
#if UNITY_IOS
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Xml.Linq;
|
|
using UnityEditor;
|
|
using UnityEditor.Callbacks;
|
|
using UnityEditor.iOS.Xcode;
|
|
using UnityEngine;
|
|
|
|
public class ChangeXcodePlistPostProcess
|
|
{
|
|
[PostProcessBuild(999999)]
|
|
public static void ChangeXcodePlist(BuildTarget buildTarget, string pathToBuiltProject)
|
|
{
|
|
if (buildTarget != BuildTarget.iOS)
|
|
return;
|
|
|
|
// Get plist
|
|
string plistPath = pathToBuiltProject + "/Info.plist";
|
|
var plist = new PlistDocument();
|
|
plist.ReadFromString(File.ReadAllText(plistPath));
|
|
var rootDict = plist.root;
|
|
|
|
#if RND_MOPUB
|
|
rootDict.SetString("GADApplicationIdentifier", Settings.MOPUB_ADMOD_APP_ID);
|
|
#endif
|
|
//IDFA
|
|
#if IS_CHINA_BUILD
|
|
rootDict.SetString("NSUserTrackingUsageDescription", "由於該應用使用了第三方框架向您投放個性化廣告,因此該請求已彈出");
|
|
#else
|
|
rootDict.SetString("NSUserTrackingUsageDescription",
|
|
"This request has popped up due to a 3rd party framework used by the app to deliver personalized ads to you");
|
|
#endif
|
|
|
|
rootDict.SetBoolean("ITSAppUsesNonExemptEncryption", false);
|
|
|
|
// Write to file
|
|
File.WriteAllText(plistPath, plist.WriteToString());
|
|
|
|
string xcodeProjectPath = Path.Combine(pathToBuiltProject, "Unity-iPhone.xcodeproj");
|
|
string pbxPath = Path.Combine(xcodeProjectPath, "project.pbxproj");
|
|
|
|
var project = new PBXProject();
|
|
project.ReadFromString(File.ReadAllText(pbxPath));
|
|
string[] targets =
|
|
{
|
|
project.ProjectGuid(),
|
|
project.GetUnityMainTargetGuid(),
|
|
project.GetUnityFrameworkTargetGuid()
|
|
};
|
|
|
|
project.SetBuildProperty(targets, "SWIFT_VERSION", "5.1");
|
|
File.WriteAllText(pbxPath, project.WriteToString());
|
|
|
|
string[] xcodeProjectLines = File.ReadAllLines(pbxPath);
|
|
var sb = new StringBuilder();
|
|
foreach (string line in xcodeProjectLines)
|
|
if (line.Contains("GCC_ENABLE_OBJC_EXCEPTIONS") ||
|
|
// line.Contains("GCC_ENABLE_CPP_EXCEPTIONS") ||
|
|
line.Contains("CLANG_ENABLE_MODULES"))
|
|
{
|
|
string newLine = line.Replace("NO", "YES");
|
|
sb.AppendLine(newLine);
|
|
}
|
|
else
|
|
{
|
|
sb.AppendLine(line);
|
|
}
|
|
|
|
File.WriteAllText(pbxPath, sb.ToString());
|
|
}
|
|
|
|
[MenuItem("Tools/PostProcessBuild/Change xcode .plist")]
|
|
public static void PostProcessBuildiOS()
|
|
{
|
|
ChangeXcodePlist(BuildTarget.iOS, Path.GetDirectoryName(Application.dataPath) + "/build_xcode/");
|
|
}
|
|
}
|
|
#endif |