|
"""
private const BindingFlags NonPublicInstanceBinding = BindingFlags.NonPublic | BindingFlags.Instance;
private const string EntitlementsArrayKey = "com.apple.developer.applesignin";
private const string DefaultAccessLevel = "Default";
private const string entitlementsPath = "game.entitlements";
"""
'''
/// <summary>
/// 修改Capability (主要是为了 苹果登录、支付、推送)
/// </summary>
private static void ModifyCapability(PBXProject proj, string unityIphone, string projectPath)
{
var capabilityManager = new ProjectCapabilityManager(projectPath, entitlementsPath, "Unity-iPhone", unityIphone);
proj.SetBuildProperty(unityIphone, "CODE_SIGN_STYLE", "Manual");
capabilityManager.AddInAppPurchase();//内购
capabilityManager.AddPushNotifications(true);//推送
capabilityManager.AddBackgroundModes(BackgroundModesOptions.RemoteNotifications);
AddSignInWithApple(capabilityManager);
capabilityManager.WriteToFile();
}
/// <summary>/// 添加苹果登录/// </summary>private static void AddSignInWithApple(ProjectCapabilityManager manager){ var managerType = typeof(ProjectCapabilityManager); var capabilityTypeType = typeof(PBXCapabilityType); var projectField = managerType.GetField("project", NonPublicInstanceBinding); var targetGuidField = managerType.GetField("m_TargetGuid", NonPublicInstanceBinding); var entitlementFilePathField = managerType.GetField("m_EntitlementFilePath", NonPublicInstanceBinding); var getOrCreateEntitlementDocMethod = managerType.GetMethod("GetOrCreateEntitlementDoc", NonPublicInstanceBinding); var constructorInfo = capabilityTypeType.GetConstructor( NonPublicInstanceBinding, null, new[] { typeof(string), typeof(bool), typeof(string), typeof(bool) }, null); if (projectField == null || targetGuidField == null || entitlementFilePathField == null || getOrCreateEntitlementDocMethod == null || constructorInfo == null) throw new Exception("Can't Add Sign In With Apple programatically in this Unity version"); var entitlementDoc = getOrCreateEntitlementDocMethod.Invoke(manager, new object[] { }) as PlistDocument; if (entitlementDoc != null) { var plistArray = new PlistElementArray(); plistArray.AddString(DefaultAccessLevel); entitlementDoc.root[EntitlementsArrayKey] = plistArray; }}
''' |
|