103 lines
5.0 KiB
C#
103 lines
5.0 KiB
C#
|
|
#if UNITY_IOS
|
|
|
|
using UnityEditor.Callbacks;
|
|
using UnityEditor.iOS.Xcode;
|
|
using UnityEditor;
|
|
using System.IO;
|
|
|
|
namespace tysdk.editor
|
|
{
|
|
|
|
public class iOSPostBuildProcessor
|
|
{
|
|
[PostProcessBuild(1000)]
|
|
public static void ChangeXcodeSettings(BuildTarget buildTarget, string pathToBuiltProject)
|
|
{
|
|
if (buildTarget == BuildTarget.iOS)
|
|
{
|
|
UnityEngine.Debug.Log($"ChangeXcodeSettings {pathToBuiltProject}");
|
|
ProcessXCodeProj(pathToBuiltProject);
|
|
}
|
|
}
|
|
|
|
private static void ProcessXCodeProj(string pathToBuiltProject)
|
|
{
|
|
string pbxprojPath = PBXProject.GetPBXProjectPath(pathToBuiltProject);
|
|
PBXProject proj = new PBXProject();
|
|
proj.ReadFromFile(pbxprojPath);
|
|
|
|
string target = proj.GetUnityMainTargetGuid();
|
|
XCodeSetSigingAndCapbilities(target, proj, pathToBuiltProject);
|
|
ProcessBuildSettings(proj);
|
|
XcodeOverwriteFiles(pathToBuiltProject, proj);
|
|
|
|
UnityEngine.Debug.Log($"XCodeProj {pbxprojPath}");
|
|
File.WriteAllText(pbxprojPath, proj.WriteToString());
|
|
|
|
//ProcessPlist(projPath);
|
|
|
|
}
|
|
|
|
private static void XcodeOverwriteFiles(string projPath, PBXProject proj)
|
|
{
|
|
var mainAppPath = Path.Combine(projPath, "Classes", "Preprocessor.h");
|
|
var mainContent = File.ReadAllText(mainAppPath);
|
|
var newContent = mainContent.Replace("#define UNITY_USES_REMOTE_NOTIFICATIONS 0", "#define UNITY_USES_REMOTE_NOTIFICATIONS 1");
|
|
File.WriteAllText(mainAppPath, newContent);
|
|
}
|
|
|
|
private static void XCodeSetSigingAndCapbilities(string target, PBXProject proj, string root)
|
|
{
|
|
var entitlementsContent = File.ReadAllText("Packages/tysdk/Files/Unity-iPhone.entitlements");
|
|
File.WriteAllText($"{root}/Unity-iPhone/Unity-iPhone.entitlements", entitlementsContent);
|
|
|
|
proj.AddCapability(target, PBXCapabilityType.KeychainSharing, "Unity-iPhone/Unity-iPhone.entitlements");
|
|
proj.AddCapability(target, PBXCapabilityType.PushNotifications, "Unity-iPhone/Unity-iPhone.entitlements");
|
|
//proj.AddCapability(target, PBXCapabilityType.AssociatedDomains, "Unity-iPhone/Unity-iPhone.entitlements");
|
|
}
|
|
|
|
private static void ProcessBuildSettings(PBXProject proj)
|
|
{
|
|
string target = proj.TargetGuidByName("GameAssembly");
|
|
proj.AddBuildProperty(target, "OTHER_LDFLAGS", "-all_load");
|
|
|
|
target = proj.TargetGuidByName("UnityFramework");
|
|
proj.AddBuildProperty(target, "OTHER_LDFLAGS", "-ObjC");
|
|
proj.AddFrameworkToProject(target, "AppTrackingTransparency.framework", false);
|
|
|
|
proj.AddFrameworkToProject(target,"StoreKit.framework", false);
|
|
proj.AddFrameworkToProject(target,"CFNetwork.framework", false);
|
|
proj.AddFrameworkToProject(target,"CoreTelephony.framework", false);
|
|
proj.AddFrameworkToProject(target,"Security.framework", false);
|
|
proj.AddFrameworkToProject(target,"SystemConfiguration.framework", false);
|
|
proj.AddFrameworkToProject(target,"libc++.tbd", false);
|
|
proj.AddFrameworkToProject(target,"libsqlite3.tbd", false);
|
|
proj.AddFrameworkToProject(target,"libz.tbd", false);
|
|
proj.AddFrameworkToProject(target,"Accelerate.framework", false);
|
|
proj.AddFrameworkToProject(target,"AuthenticationServices.framework", false);
|
|
proj.AddFrameworkToProject(target,"SafariServices.framework", false);
|
|
proj.AddFrameworkToProject(target,"LocalAuthentication.framework", false);
|
|
proj.AddFrameworkToProject(target,"CoreGraphics.framework", false);
|
|
proj.AddFrameworkToProject(target,"WebKit.framework", false);
|
|
}
|
|
|
|
private static void ProcessPlist(string root)
|
|
{
|
|
var trackingDescription = "Data will be used to deliver personalized content to you";
|
|
var photoLibraryUsageDescription = "The app requires your consent to add photos or videos to the photo gallery so that you can manage and share them more easily. We are committed to protecting your privacy and complying with relevant laws and regulations.";
|
|
string plistPath = root + "/Info.plist";
|
|
PlistDocument plist = new PlistDocument();
|
|
plist.ReadFromString(File.ReadAllText(plistPath));
|
|
PlistElementDict infoDict = plist.root;
|
|
infoDict.SetString("NSUserTrackingUsageDescription", trackingDescription);
|
|
infoDict.SetBoolean("UIFileSharingEnabled", true);
|
|
infoDict.SetBoolean("PHPhotoLibraryPreventAutomaticLimitedAccessAlert", true);
|
|
infoDict.SetString("NSPhotoLibraryUsageDescription", photoLibraryUsageDescription);
|
|
File.WriteAllText(plistPath, plist.WriteToString());
|
|
}
|
|
}
|
|
}
|
|
|
|
#endif
|