找回密码
 立即注册
查看: 265|回复: 0

Unity IOS 添加苹果登录、支付、推送

[复制链接]
发表于 2022-12-8 09:41 | 显示全部楼层 |阅读模式
"""
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;    }}
'''
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-11-15 20:49 , Processed in 0.132557 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表