static ProjectCapabilityManager GenerateAppLinksEntitlements(string projectPath, IEnumerable <string> domains) { var entitlements = new ProjectCapabilityManager( projectPath, "com.unity.reflect.entitlements", "Unity-iPhone"); var appLinks = domains.Select(domain => $"applinks:{domain}").ToArray(); entitlements.AddAssociatedDomains(appLinks); return(entitlements); }
public void AddAssociatedDomainsWorks() { SetupTestProject(); ResetGuidGenerator(); var capManager = new ProjectCapabilityManager(PBXProject.GetPBXProjectPath(GetTestOutputPath()), "test.entitlements", PBXProject.GetUnityTargetName()); capManager.AddAssociatedDomains(new string[] { "webcredentials:example.com", "webcredentials:example2.com" }); capManager.WriteToFile(); TestOutputProject(capManager.project, "add_associateddomains.pbxproj"); TestOutput("test.entitlements", "add_associateddomains.entitlements"); }
private static void AddCapability(MOBXCodeEditorModel xcodeModel, PBXProject xcodeProj, string xcodeTargetGuid, string xcodeTargetPath) { string projectPath = PBXProject.GetPBXProjectPath(xcodeTargetPath); if (xcodeModel.isOpenRestoreScene || xcodeModel.isHaveApple) { string entitlementsPath = xcodeModel.entitlementsPath; if (entitlementsPath == null || entitlementsPath == "" || !xcodeModel.entitlementsPath.Contains(".entitlements")) { string[] s = UnityEditor.PlayerSettings.applicationIdentifier.Split('.'); string productname = s[s.Length - 1]; entitlementsPath = "Unity-iPhone/" + productname + ".entitlements"; } ProjectCapabilityManager capManager = new ProjectCapabilityManager(projectPath, entitlementsPath, PBXProject.GetUnityTargetName()); if (xcodeModel.associatedDomains.Count > 0 || xcodeModel.isHaveApple) { string[] domains = new string[xcodeModel.associatedDomains.Count]; int index = 0; foreach (string domainStr in xcodeModel.associatedDomains) { domains[index] = domainStr; index++; } capManager.AddAssociatedDomains(domains); if (xcodeModel.isHaveApple && capManager.GetType().GetMethod("AddSignInWithApple") != null) { capManager.GetType().GetMethod("AddSignInWithApple").Invoke(capManager, null); } //推送 //capManager.AddPushNotifications(true); //内购 //capManager.AddInAppPurchase(); capManager.WriteToFile(); //Debug.Log("AddCapabilityAssociatedDomains"); //Debug.Log("xcodeTargetGuid:" + xcodeTargetGuid); //Debug.Log("xcodeTargetPath:" + xcodeTargetPath); //Debug.Log("projectPath:" + projectPath); //Debug.Log("GetUnityTargetName:" + PBXProject.GetUnityTargetName()); //Debug.Log("bundleIdentifier:" + UnityEditor.PlayerSettings.applicationIdentifier); //Debug.Log("productName:" + UnityEditor.PlayerSettings.productName); xcodeProj.AddCapability(xcodeTargetGuid, PBXCapabilityType.AssociatedDomains, xcodeTargetPath + "/" + xcodeModel.entitlementsPath, true); } } }
public static void ChangeEntitlements(string pathToBuiltProject) { //This is the default path to the default pbxproj file. Yours might be different string projectPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj"; //Default target name. Yours might be different string targetName = "Unity-iPhone"; //Set the entitlements file name to what you want but make sure it has this extension string entitlementsFileName = "branch_domains.entitlements"; var entitlements = new ProjectCapabilityManager(projectPath, entitlementsFileName, targetName); entitlements.AddAssociatedDomains(BuildEntitlements()); //Apply entitlements.WriteToFile(); }
/// <summary> /// 添加Capability /// </summary> private void AddCapability(ProjectCapabilityManager capManager) { var arr = GenerateAssociatedDomainList().ToArray(); for (var i = 0; i < arr.Length; i++) { if (!arr[i].StartsWith("applinks:")) { arr[i] = $"applinks:{arr[i]}"; } } capManager.AddAssociatedDomains(arr); capManager.WriteToFile(); }
//设置Capabilities void SetCapabilities(string pathToBuildProject) { string projPath = pathToBuildProject + "/Unity-iPhone.xcodeproj/project.pbxproj"; //项目路径,这个路径在mac上默认是不显示的,需要右键->显示包内容才能看到。unity到处的名字就是这个。 UnityEditor.iOS.Xcode.PBXProject pbxProj = new UnityEditor.iOS.Xcode.PBXProject(); //创建xcode project类 pbxProj.ReadFromString(File.ReadAllText(projPath)); //xcode project读入 string targetGuid = pbxProj.TargetGuidByName(PBXProject.GetUnityTargetName()); //获得Target名 //设置BuildSetting pbxProj.SetBuildProperty(targetGuid, "ENABLE_BITCODE", "NO"); pbxProj.AddBuildProperty(targetGuid, "OTHER_LDFLAGS", "-ObjC"); pbxProj.SetBuildProperty(targetGuid, "DEBUG_INFORMATION_FORMAT", "dwarf-with-dsym"); //定位崩溃bug pbxProj.SetBuildProperty(targetGuid, "EXCLUDED_ARCHS", "armv7"); pbxProj.AddFrameworkToProject(targetGuid, "MediaPlayer.framework", false); pbxProj.AddFrameworkToProject(targetGuid, "AdSupport.framework", true); //添加资源 pbxProj.AddFileToBuild(targetGuid, pbxProj.AddFile(System.Environment.CurrentDirectory + "/LTBaseSDK_Oversea/ltgame.cfg", "Resource/ltgame.cfg", PBXSourceTree.Source)); //修改编译方式 string mmfile = pbxProj.FindFileGuidByProjectPath("Classes/UnityAppController.mm"); var flags = pbxProj.GetCompileFlagsForFile(targetGuid, mmfile); flags.Add("-fno-objc-arc"); pbxProj.SetCompileFlagsForFile(targetGuid, mmfile, flags); mmfile = pbxProj.FindFileGuidByProjectPath("Libraries/Plugins/IOS/LTSDK/LTSDKNPC.mm"); flags = pbxProj.GetCompileFlagsForFile(targetGuid, mmfile); flags.Add("-fno-objc-arc"); pbxProj.SetCompileFlagsForFile(targetGuid, mmfile, flags); pbxProj.WriteToFile(projPath); string[] splits = PlayerSettings.applicationIdentifier.Split('.'); var capManager = new ProjectCapabilityManager(projPath, splits[splits.Length - 1] + ".entitlements", PBXProject.GetUnityTargetName());//创建设置Capability类 if (PlayerSettings.applicationIdentifier.Equals("com.longtugame.dzyz.longtu")) { //正式包,增加计费 capManager.AddInAppPurchase(); } capManager.AddAssociatedDomains(new[] { "applinks:dy.longtugame.com" }); capManager.WriteToFile();//写入文件保存 }
private static void EditCapacity(string path, string targetName, ProductConfig product) { var projPath = PBXProject.GetPBXProjectPath(path); var cap = new ProjectCapabilityManager(projPath, product.EntitlementFile, targetName); cap.AddInAppPurchase(); cap.AddKeychainSharing(new[] { product.KeyChainGroup }); var links = product.UniversalLinks; if (links != null && links.Count > 0) { cap.AddAssociatedDomains(links.ToArray()); } cap.WriteToFile(); }
private static void ApplyCrosspromoDynamicLinks(string buildPath, string targetGuid, CASInitSettings casSettings, DependencyManager deps) { if (!casSettings || casSettings.IsTestAdMode() || casSettings.managersCount == 0 || string.IsNullOrEmpty(casSettings.GetManagerId(0))) { return; } if (deps != null) { var crossPromoDependency = deps.FindCrossPromotion(); if (crossPromoDependency != null && !crossPromoDependency.IsInstalled()) { return; } } try { var identifier = Application.identifier; var productName = identifier.Substring(identifier.LastIndexOf(".") + 1); var projectPath = GetXCodeProjectPath(buildPath); var entitlements = new ProjectCapabilityManager(projectPath, productName + ".entitlements", #if UNITY_2019_3_OR_NEWER null, targetGuid); #else PBXProject.GetUnityTargetName()); #endif string link = "applinks:psvios" + casSettings.GetManagerId(0) + ".page.link"; entitlements.AddAssociatedDomains(new[] { link }); entitlements.WriteToFile(); Debug.Log(CASEditorUtils.logTag + "Apply application shame: " + link); } catch (Exception e) { Debug.LogError(CASEditorUtils.logTag + "Dynamic link creation fail: " + e.ToString()); } }
static void AddCapabilities(PBXProject proj, string targetGuid, ProjectCapabilityManager capManager) { var capability = ISD_Settings.Instance.Capability; if (capability.iCloud.Enabled) { if (capability.iCloud.iCloudDocument || capability.iCloud.customContainers.Count > 0) { capManager.AddiCloud(capability.iCloud.keyValueStorage, capability.iCloud.iCloudDocument, capability.iCloud.customContainers.ToArray()); } else { capManager.AddiCloud(capability.iCloud.keyValueStorage, false, null); } } if (capability.PushNotifications.Enabled) { capManager.AddPushNotifications(capability.PushNotifications.development); } if (capability.GameCenter.Enabled) { capManager.AddGameCenter(); } if (capability.Wallet.Enabled) { capManager.AddWallet(capability.Wallet.passSubset.ToArray()); } if (capability.Siri.Enabled) { capManager.AddSiri(); } if (capability.ApplePay.Enabled) { capManager.AddApplePay(capability.ApplePay.merchants.ToArray()); } if (capability.InAppPurchase.Enabled) { capManager.AddInAppPurchase(); } if (capability.Maps.Enabled) { var options = MapsOptions.None; foreach (var opt in capability.Maps.options) { MapsOptions opt2 = (MapsOptions)opt; options |= opt2; } capManager.AddMaps(options); } if (capability.PersonalVPN.Enabled) { capManager.AddPersonalVPN(); } if (capability.BackgroundModes.Enabled) { var options = BackgroundModesOptions.None; foreach (var opt in capability.BackgroundModes.options) { BackgroundModesOptions opt2 = (BackgroundModesOptions)opt; options |= opt2; } capManager.AddBackgroundModes(options); } if (capability.InterAppAudio.Enabled) { capManager.AddInterAppAudio(); } if (capability.KeychainSharing.Enabled) { capManager.AddKeychainSharing(capability.KeychainSharing.accessGroups.ToArray()); } if (capability.AssociatedDomains.Enabled) { capManager.AddAssociatedDomains(capability.AssociatedDomains.domains.ToArray()); } if (capability.AppGroups.Enabled) { capManager.AddAppGroups(capability.AppGroups.groups.ToArray()); } if (capability.DataProtection.Enabled) { capManager.AddDataProtection(); } if (capability.HomeKit.Enabled) { capManager.AddHomeKit(); } if (capability.HealthKit.Enabled) { capManager.AddHealthKit(); } if (capability.WirelessAccessoryConfiguration.Enabled) { capManager.AddWirelessAccessoryConfiguration(); } /* * * * if (ISD_Settings.Instance.Capabilities.Count == 0) { * return; * } * * * foreach (var cap in ISD_Settings.Instance.Capabilities) { * switch(cap.CapabilityType) { * * * case ISD_CapabilityType.InAppPurchase: * capManager.AddInAppPurchase(); * break; * case ISD_CapabilityType.GameCenter: * capManager.AddGameCenter(); * break; * case ISD_CapabilityType.PushNotifications: * var pushSettings = ISD_Settings.Instance.PushNotificationsCapabilitySettings; * capManager.AddPushNotifications(pushSettings.Development); * break; * * default: * var capability = ISD_PBXCapabilityTypeUtility.ToPBXCapability(cap.CapabilityType); * string entitlementsFilePath = null; * if(!string.IsNullOrEmpty(cap.EntitlementsFilePath)) { * entitlementsFilePath = cap.EntitlementsFilePath; * } * * * proj.AddCapability(targetGuid, capability, entitlementsFilePath, cap.AddOptionalFramework); * break; * } * } */ }
private static void AddCapabilities(ProjectCapabilityManager capManager) { var capability = ISD_Settings.Instance.Capability; if (capability.iCloud.Enabled) { if (capability.iCloud.iCloudDocument || capability.iCloud.customContainers.Count > 0) { capManager.AddiCloud(capability.iCloud.keyValueStorage, capability.iCloud.iCloudDocument, capability.iCloud.customContainers.ToArray()); } else { capManager.AddiCloud(capability.iCloud.keyValueStorage, false, null); } } if (capability.PushNotifications.Enabled) { capManager.AddPushNotifications(capability.PushNotifications.development); } if (capability.GameCenter.Enabled) { capManager.AddGameCenter(); } if (capability.Wallet.Enabled) { capManager.AddWallet(capability.Wallet.passSubset.ToArray()); } if (capability.Siri.Enabled) { capManager.AddSiri(); } if (capability.ApplePay.Enabled) { capManager.AddApplePay(capability.ApplePay.merchants.ToArray()); } if (capability.InAppPurchase.Enabled) { capManager.AddInAppPurchase(); } if (capability.Maps.Enabled) { var options = MapsOptions.None; foreach (var opt in capability.Maps.options) { MapsOptions opt2 = (MapsOptions)opt; options |= opt2; } capManager.AddMaps(options); } if (capability.PersonalVPN.Enabled) { capManager.AddPersonalVPN(); } if (capability.BackgroundModes.Enabled) { var options = BackgroundModesOptions.None; foreach (var opt in capability.BackgroundModes.options) { BackgroundModesOptions opt2 = (BackgroundModesOptions)opt; options |= opt2; } capManager.AddBackgroundModes(options); } if (capability.InterAppAudio.Enabled) { capManager.AddInterAppAudio(); } if (capability.KeychainSharing.Enabled) { capManager.AddKeychainSharing(capability.KeychainSharing.accessGroups.ToArray()); } if (capability.AssociatedDomains.Enabled) { capManager.AddAssociatedDomains(capability.AssociatedDomains.domains.ToArray()); } if (capability.AppGroups.Enabled) { capManager.AddAppGroups(capability.AppGroups.groups.ToArray()); } if (capability.DataProtection.Enabled) { capManager.AddDataProtection(); } if (capability.HomeKit.Enabled) { capManager.AddHomeKit(); } if (capability.HealthKit.Enabled) { capManager.AddHealthKit(); } if (capability.WirelessAccessoryConfiguration.Enabled) { capManager.AddWirelessAccessoryConfiguration(); } }
public static void OnPostprocessBuild(BuildTarget build_target, string path) { if (build_target != BuildTarget.iOS) return; string proj_path = PBXProject.GetPBXProjectPath(path); PBXProject proj = new PBXProject(); proj.ReadFromString(File.ReadAllText(proj_path)); // 获取当前项目名字 string target = proj.TargetGuidByName(PBXProject.GetUnityTargetName()); // 对所有的编译配置设置选项 proj.SetBuildProperty(target, "ENABLE_BITCODE", "NO"); // 添加依赖库 proj.AddFrameworkToProject(target, "libc++.dylib", false); proj.AddFrameworkToProject(target, "libsqlite3.dylib", false); proj.AddFrameworkToProject(target, "libz.dylib", false); proj.AddFrameworkToProject(target, "libc++.tbd", false); proj.AddFrameworkToProject(target, "libicucore.tbd", false); proj.AddFrameworkToProject(target, "libsqlite3.tbd", false); proj.AddFrameworkToProject(target, "libz.tbd", false); proj.AddFrameworkToProject(target, "libz.1.2.5.tbd", false); proj.AddFrameworkToProject(target, "Accelerate.framework", false); proj.AddFrameworkToProject(target, "AudioToolbox.framework", false); proj.AddFrameworkToProject(target, "AVFoundation.framework", false); proj.AddFrameworkToProject(target, "CFNetwork.framework", false); proj.AddFrameworkToProject(target, "CoreLocation.framework", false); proj.AddFrameworkToProject(target, "CoreMedia.framework", false); proj.AddFrameworkToProject(target, "CoreMotion.framework", false); proj.AddFrameworkToProject(target, "CoreTelephony.framework", false); proj.AddFrameworkToProject(target, "CoreVideo.framework", false); proj.AddFrameworkToProject(target, "JavaScriptCore.framework", true);// 设置为Optional proj.AddFrameworkToProject(target, "MessageUI.framework", false); proj.AddFrameworkToProject(target, "MobileCoreServices.framework", false); proj.AddFrameworkToProject(target, "PushKit.framework", true); proj.AddFrameworkToProject(target, "Security.framework", false);// 用于存储keychain proj.AddFrameworkToProject(target, "SystemConfiguration.framework", false);// 用于读取异常发生时的系统信息 proj.AddFrameworkToProject(target, "UserNotifications.framework", true); // 设置签名 //proj.SetBuildProperty (target, "CODE_SIGN_IDENTITY", "iPhone Distribution: _______________"); //proj.SetBuildProperty (target, "PROVISIONING_PROFILE", "********-****-****-****-************"); //string debugConfig = proj.BuildConfigByName(target, "Debug"); //string releaseConfig = proj.BuildConfigByName(target, "Release"); //proj.SetBuildPropertyForConfig(debugConfig, "PROVISIONING_PROFILE", "证书"); //proj.SetBuildPropertyForConfig(releaseConfig, "PROVISIONING_PROFILE", "证书"); //proj.SetBuildPropertyForConfig(debugConfig, "PROVISIONING_PROFILE(Deprecated)", "证书"); //proj.SetBuildPropertyForConfig(releaseConfig, "PROVISIONING_PROFILE(Deprecated)", "证书"); //proj.SetBuildPropertyForConfig(debugConfig, "CODE_SIGN_IDENTITY", "自己的证书"); //proj.SetBuildPropertyForConfig(releaseConfig, "CODE_SIGN_IDENTITY", "自己的证书"); //proj.SetTeamId(target, "Team ID(自己的teamid)"); //proj.AddCapability(target, PBXCapabilityType.AssociatedDomains); // 保存工程 proj.WriteToFile(proj_path); ProjectCapabilityManager proj_capability_mgr = new ProjectCapabilityManager(proj_path, "KingNative.entitlements", PBXProject.GetUnityTargetName()); proj_capability_mgr.AddAssociatedDomains(new string[] { "applinks:znc4d4.openinstall.io" });// OpenInstall proj_capability_mgr.AddPushNotifications(false); proj_capability_mgr.AddBackgroundModes(BackgroundModesOptions.RemoteNotifications); proj_capability_mgr.WriteToFile(); // 修改plist string plist_path = path + "/Info.plist"; PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plist_path)); PlistElementDict root_dict = plist.root; root_dict.SetString("com.openinstall.APP_KEY", "znc4d4");// OpenInstall // NativeToolkit root_dict.SetString("NSPhotoLibraryUsageDescription", "Requires access to the Photo Library"); root_dict.SetString("NSPhotoLibraryAddUsageDescription", "Requires access to the Photo Library"); root_dict.SetString("NSCameraUsageDescription", "Requires access to the Camera"); root_dict.SetString("NSContactsUsageDescription", "Requires access to Contacts"); root_dict.SetString("NSLocationAlwaysUsageDescription", "Requires access to Location"); root_dict.SetString("NSLocationWhenInUseUsageDescription", "Requires access to Location"); root_dict.SetString("NSLocationAlwaysAndWhenInUseUsageDescription", "Requires access to Location"); // 保存plist plist.WriteToFile(plist_path); #endif }
static void OnPostprocessBuild(BuildTarget target, string pathToBuildProject) { string projPath = PBXProject.GetPBXProjectPath(pathToBuildProject); PBXProject proj = new PBXProject(); proj.ReadFromString(File.ReadAllText(projPath)); var targetGuid = proj.GetUnityMainTargetGuid();// ("Unity-iPhone"); var frameworkTarget = proj.GetUnityFrameworkTargetGuid(); //Wechat関連1、Security,WebKit,CoreLocation 三つのフレームワークが必要。 proj.AddFrameworkToProject(targetGuid, "Security.framework", false); proj.AddFrameworkToProject(targetGuid, "WebKit.framework", false); proj.AddFrameworkToProject(targetGuid, "CoreLocation.framework", false); proj.AddFrameworkToProject(frameworkTarget, "Security.framework", false); proj.AddFrameworkToProject(frameworkTarget, "WebKit.framework", false); proj.AddFrameworkToProject(frameworkTarget, "CoreLocation.framework", false); //Wechat関連2、他のプロプーティ proj.SetBuildProperty(targetGuid, "ENABLE_BITCODE", "No"); proj.AddBuildProperty(targetGuid, "OTHER_LDFLAGS", "-Objc"); proj.AddBuildProperty(targetGuid, "OTHER_LDFLAGS", "-all_load"); proj.SetBuildProperty(frameworkTarget, "ENABLE_BITCODE", "No"); //must. proj.AddBuildProperty(frameworkTarget, "OTHER_LDFLAGS", "-Objc"); proj.AddBuildProperty(frameworkTarget, "OTHER_LDFLAGS", "-all_load"); //TODO use the teamId of yourself. proj.SetBuildProperty(targetGuid, "DEVELOPMENT_TEAM", "LY5UJF7S34"); File.WriteAllText(projPath, proj.WriteToString()); /* * string plistPath = pathToBuildProject + "/Info.plist"; * PlistDocument plist = new PlistDocument(); * plist.ReadFromString(File.ReadAllText(plistPath)); * PlistElementArray lsSchems = plist.root.CreateArray("LSApplicationQueriesSchemes"); * lsSchems.AddString("weixin"); * lsSchems.AddString("weixinULAPI"); * PlistElementDict rootDict = plist.root; * PlistElementArray urlTypes = rootDict.CreateArray("CFBundleURLTypes"); * PlistElementDict wxUrl = urlTypes.AddDict(); * wxUrl.SetString("CFBundleTypeRole", "Editor"); * wxUrl.SetString("CFBundleURLName", "weixin"); * PlistElementArray wxUrlSheme = wxUrl.CreateArray("CFBundleURLSchemes"); * wxUrlSheme.AddString("wx7a3c7293fe47ea6a"); */ // info.plist var plistPath = Path.Combine(pathToBuildProject, "Info.plist"); var plist = new PlistDocument(); plist.ReadFromFile(plistPath); //Wechat関連5、info.plist変更、WhiteListにウェチャットを追加。(Lineと同じい) PlistElementArray lsSchemes = plist.root.CreateArray("LSApplicationQueriesSchemes"); lsSchemes.AddString("weixin"); lsSchemes.AddString("weixinULAPI"); //Wechat関連6、info.plist変更、ウェチャットからジャンプバック用。(Lineと同じい) PlistElementDict rootDict = plist.root; PlistElementArray urlTypes = rootDict.CreateArray("CFBundleURLTypes"); PlistElementDict wxUrl = urlTypes.AddDict(); wxUrl.SetString("CFBundleTypeRole", "Editor"); wxUrl.SetString("CFBundleURLName", "weixin"); PlistElementArray wxUrlSheme = wxUrl.CreateArray("CFBundleURLSchemes"); //TODO wechat申請次第。 //wxUrlSheme.AddString("wx7a3c7293fe47ea6a"); //wxd930ea5d5a258f4f wxUrlSheme.AddString(Wechat.WechatSample.WechatAppId); plist.WriteToFile(plistPath); //注意,必须放到最后,避免被覆盖。 //Wechat関連3、Associated Domains設定(Universal Link用、Wechatから呼び出す用かなぁ) ProjectCapabilityManager capManager = new ProjectCapabilityManager(projPath, "crosslink.entitlements", null, targetGuid); //yingyugang.s3-ap-northeast-1.amazonaws.com,TODO PR時に公式のリンkを書き換え必要。 //var array = new string[] { "applinks:yingyugang.s3-ap-northeast-1.amazonaws.com" }; var array = new string[] { Wechat.WechatSample.AccosiateDemain }; capManager.AddAssociatedDomains(array); capManager.WriteToFile(); }