2021-04-07 16:20:41 +08:00
|
|
|
|
using System.IO;
|
|
|
|
|
using TapTap.Common.Editor;
|
|
|
|
|
using UnityEditor;
|
|
|
|
|
using UnityEditor.Callbacks;
|
|
|
|
|
using UnityEditor.iOS.Xcode;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace TapTap.Bootstrap.Editor
|
|
|
|
|
{
|
|
|
|
|
public static class TapBootstrapIOSProcessor
|
|
|
|
|
{
|
|
|
|
|
// 添加标签,unity导出工程后自动执行该函数
|
|
|
|
|
[PostProcessBuild(100)]
|
|
|
|
|
public static void OnPostprocessBuild(BuildTarget buildTarget, string path)
|
|
|
|
|
{
|
|
|
|
|
if (buildTarget != BuildTarget.iOS) return;
|
|
|
|
|
// 获得工程路径
|
|
|
|
|
var projPath = TapCommonCompile.GetProjPath(path);
|
|
|
|
|
var proj = TapCommonCompile.ParseProjPath(projPath);
|
|
|
|
|
var target = TapCommonCompile.GetUnityTarget(proj);
|
|
|
|
|
|
|
|
|
|
if (TapCommonCompile.CheckTarget(target))
|
|
|
|
|
{
|
|
|
|
|
Debug.LogError("Unity-iPhone is NUll");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var parentFolder = Directory.GetParent(Application.dataPath).FullName;
|
|
|
|
|
|
|
|
|
|
var plistFile = TapFileHelper.RecursionFilterFile(parentFolder + "/Assets/Plugins/", "TDS-Info.plist");
|
|
|
|
|
|
|
|
|
|
if (!plistFile.Exists)
|
|
|
|
|
{
|
|
|
|
|
Debug.LogError("TapSDK Can't find TDS-Info.plist in Project/Assets/Plugins/!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TapCommonCompile.HandlerPlist(path, plistFile.FullName);
|
|
|
|
|
|
|
|
|
|
HandlerAppleSignIn(proj, target, path, plistFile.FullName);
|
|
|
|
|
|
|
|
|
|
if (TapCommonCompile.HandlerIOSSetting(path,
|
|
|
|
|
Application.dataPath,
|
|
|
|
|
"TapBootstrapResource",
|
2021-04-09 18:35:23 +08:00
|
|
|
|
"com.taptap.tds.bootstrap",
|
2021-04-07 16:20:41 +08:00
|
|
|
|
"Bootstrap",
|
|
|
|
|
new[] {"TapBootstrapResource.bundle"},
|
|
|
|
|
target, projPath, proj))
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("TapBootstrap add Bundle Success!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Debug.LogError("TapBootstrap add Bundle Failed!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void HandlerAppleSignIn(PBXProject proj, string target, string path, string plistPath)
|
|
|
|
|
{
|
|
|
|
|
var appleSignInEnable = TapCommonCompile.GetValueFromPlist(plistPath, "Apple_SignIn_Enable");
|
|
|
|
|
var appleSignInEnableKey = "com.apple.developer.applesignin";
|
|
|
|
|
if (string.IsNullOrEmpty(appleSignInEnable) || appleSignInEnable.Equals("false"))
|
|
|
|
|
{
|
2021-04-09 19:05:17 +08:00
|
|
|
|
Debug.LogWarning("TapSDK can't open Apple SignIn in XCode, Please Check Info.plist.");
|
2021-04-07 16:20:41 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var entitleFilePath = $"{path}/Unity-iPhone.entitlements";
|
|
|
|
|
var tempEntitlements = new PlistDocument();
|
|
|
|
|
if (!((tempEntitlements.root[appleSignInEnableKey] = new PlistElementArray()) is PlistElementArray arrSigninWithApple))
|
|
|
|
|
{
|
2021-04-09 19:05:17 +08:00
|
|
|
|
Debug.LogWarning($"TapSDK can't find {appleSignInEnableKey}.");
|
2021-04-07 16:20:41 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
arrSigninWithApple.values.Add(new PlistElementString("Default"));
|
|
|
|
|
proj.AddCapability(target, PBXCapabilityType.SignInWithApple, entitleFilePath);
|
|
|
|
|
tempEntitlements.WriteToFile(entitleFilePath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|