private static void AddNFCCapability(string path) { string projectPath = PBXProject.GetPBXProjectPath(path); //PBXProject project = new PBXProject(); //project.ReadFromFile(projectPath); String packageName = UnityEngine.Application.identifier; String name = packageName.Substring(packageName.LastIndexOf('.') + 1); String entitlementFileName = name + ".entitlements"; String entitlementPath = Path.Combine(path, entitlementFileName); ProjectCapabilityManager projectCapabilityManager = new ProjectCapabilityManager(projectPath, entitlementFileName, PBXProject.GetUnityTargetName()); PlistDocument entitlementDocument = AddNFCEntitlement(projectCapabilityManager); entitlementDocument.WriteToFile(entitlementPath); var projectInfo = projectCapabilityManager.GetType().GetField("project", BindingFlags.NonPublic | BindingFlags.Instance); PBXProject project = (PBXProject)projectInfo.GetValue(projectCapabilityManager); string target = project.TargetGuidByName(PBXProject.GetUnityTargetName()); var constructor = typeof(PBXCapabilityType).GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { typeof(string), typeof(bool), typeof(string), typeof(bool) }, null); PBXCapabilityType nfcCapability = (PBXCapabilityType)constructor.Invoke(new object[] { "com.apple.NearFieldCommunicationTagReading", true, "", false }); project.AddCapability(target, nfcCapability, entitlementFileName); projectCapabilityManager.WriteToFile(); }
private static void PostProcessIOSandTVOS(string path) { var settings = GetBuildSettings(); if (settings.EnablePostProcessIOSandTVOS == false) { Debug.Log("[HovelHouse.CloudKit] skipping post process build step..."); return; } string pbxPath = PBXProject.GetPBXProjectPath(path); var pbxProject = new PBXProject(); pbxProject.ReadFromFile(pbxPath); var name = PlayerSettings.applicationIdentifier.Split('.').Last(); #if UNITY_2019_3_OR_NEWER ProjectCapabilityManager projCapability = new ProjectCapabilityManager( pbxPath, name + ".entitlements", null, pbxProject.GetUnityMainTargetGuid()); #else ProjectCapabilityManager projCapability = new ProjectCapabilityManager( pbxPath, name + ".entitlements", PBXProject.GetUnityTargetName()); #endif projCapability.AddiCloud( settings.EnableKeyVaueStorage, settings.EnableDocumentStorage, settings.EnableCloudKit, settings.AddDefaultContainers, settings.CustomContainers); projCapability.WriteToFile(); }
public void OnPostprocessBuild(BuildReport report) { #if UNITY_IOS BuildTarget buildTarget = report.summary.platform; string path = report.summary.outputPath; if (buildTarget != BuildTarget.iOS) { return; } string projPath = PBXProject.GetPBXProjectPath(path); // buid settings PBXProject proj = new PBXProject(); proj.ReadFromFile(projPath); var targetGuid = proj.TargetGuidByName(PBXProject.GetUnityTargetName()); proj.SetBuildProperty(targetGuid, "VALIDATE_WORKSPACE", "True"); proj.SetBuildProperty(targetGuid, "SWIFT_VERSION", "5.0"); // capabilities ProjectCapabilityManager manager = new ProjectCapabilityManager( projPath, "Entitlements.entitlements", PBXProject.GetUnityTargetName() ); manager.AddSignInWithApple(); manager.AddPushNotifications(false); // save setup manager.WriteToFile(); proj.WriteToFile(projPath); #endif }
private static void addCapability(string pathToBuiltProject, string projPath, PBXProject proj, string target) { var dummy = CreateInstance <XcodeBuildScript>(); var entitlementsFile = dummy.entitlementsFile; DestroyImmediate(dummy); // Copy the entitlement file to the xcode project var entitlementPath = AssetDatabase.GetAssetPath(entitlementsFile); var entitlementFileName = Path.GetFileName(entitlementPath); var unityTarget = PBXProject.GetUnityTargetName(); var relativeDestination = unityTarget + "/" + entitlementFileName; var desPath = pathToBuiltProject + "/" + relativeDestination; if (File.Exists(desPath)) { File.Delete(desPath); } FileUtil.CopyFileOrDirectory(entitlementPath, desPath); // Add the pbx configs to include the entitlements files on the project proj.AddFile(relativeDestination, entitlementFileName); proj.AddBuildProperty(target, "CODE_SIGN_ENTITLEMENTS", relativeDestination); // Add Capability var capManager = new ProjectCapabilityManager(projPath, entitlementFileName, unityTarget); capManager.AddPushNotifications(true); capManager.AddInAppPurchase(); capManager.WriteToFile(); }
static void SetupXCodeProject(string _buildPath) { string projectPath = PBXProject.GetPBXProjectPath(_buildPath); PBXProject project = new PBXProject(); project.ReadFromString(File.ReadAllText(projectPath)); string targetName = PBXProject.GetUnityTargetName(); string targetGuid = project.TargetGuidByName(targetName); // Move the entitlement file to from root directory to target directory. string entitleFileSource = _buildPath + "/" + entitlementsFileName; string entitleFileDestination = _buildPath + "/" + targetName + "/" + entitlementsFileName; FileUtil.MoveFileOrDirectory(entitleFileSource, entitleFileDestination); project.AddFile(targetName + "/" + entitlementsFileName, entitlementsFileName); project.AddBuildProperty(targetGuid, "HEADER_SEARCH_PATHS", "$(SRCROOT)/NativeFramework"); ProjectCapabilityManager capabilityManager = new ProjectCapabilityManager(projectPath, entitlementsFileName, targetName); capabilityManager.AddBackgroundModes(BackgroundModesOptions.RemoteNotifications); capabilityManager.WriteToFile(); project.AddBuildProperty(targetGuid, "CODE_SIGN_ENTITLEMENTS", targetName + "/" + entitlementsFileName); project.AddCapability(targetGuid, PBXCapabilityType.GameCenter); project.AddCapability(targetGuid, PBXCapabilityType.InAppPurchase); File.WriteAllText(projectPath, project.WriteToString()); }
private static void PatchPBXProject(string path, bool needLocationFramework, bool addPushNotificationCapability, bool useReleaseAPSEnv) { var pbxProjectPath = PBXProject.GetPBXProjectPath(path); var needsToWriteChanges = false; var pbxProject = new PBXProject(); pbxProject.ReadFromString(File.ReadAllText(pbxProjectPath)); string mainTarget; string unityFrameworkTarget; var unityMainTargetGuidMethod = pbxProject.GetType().GetMethod("GetUnityMainTargetGuid"); var unityFrameworkTargetGuidMethod = pbxProject.GetType().GetMethod("GetUnityFrameworkTargetGuid"); if (unityMainTargetGuidMethod != null && unityFrameworkTargetGuidMethod != null) { mainTarget = (string)unityMainTargetGuidMethod.Invoke(pbxProject, null); unityFrameworkTarget = (string)unityFrameworkTargetGuidMethod.Invoke(pbxProject, null); } else { mainTarget = pbxProject.TargetGuidByName("Unity-iPhone"); unityFrameworkTarget = mainTarget; } // Add necessary frameworks. if (!pbxProject.ContainsFramework(unityFrameworkTarget, "UserNotifications.framework")) { pbxProject.AddFrameworkToProject(unityFrameworkTarget, "UserNotifications.framework", true); needsToWriteChanges = true; } if (needLocationFramework && !pbxProject.ContainsFramework(unityFrameworkTarget, "CoreLocation.framework")) { pbxProject.AddFrameworkToProject(unityFrameworkTarget, "CoreLocation.framework", false); needsToWriteChanges = true; } if (needsToWriteChanges) { File.WriteAllText(pbxProjectPath, pbxProject.WriteToString()); } // Update the entitlements file. if (addPushNotificationCapability) { var entitlementsFileName = pbxProject.GetBuildPropertyForAnyConfig(mainTarget, "CODE_SIGN_ENTITLEMENTS"); if (entitlementsFileName == null) { var bundleIdentifier = PlayerSettings.GetApplicationIdentifier(BuildTargetGroup.iOS); entitlementsFileName = string.Format("{0}.entitlements", bundleIdentifier.Substring(bundleIdentifier.LastIndexOf(".") + 1)); } var capManager = new ProjectCapabilityManager(pbxProjectPath, entitlementsFileName, "Unity-iPhone"); capManager.AddPushNotifications(!useReleaseAPSEnv); capManager.WriteToFile(); } }
public static void OnPostprocessBuild(BuildTarget buildTarget, string buildPath) { string pbxPath = PBXProject.GetPBXProjectPath(buildPath); var capManager = new ProjectCapabilityManager(pbxPath, "ios.entitlements", "Unity-iPhone"); capManager.AddiCloud(true, false, false, true, null); capManager.WriteToFile(); }
protected override void Process(BuildTarget target, string buildPath) { ProjectCapabilityManager capabilities = new ProjectCapabilityManager(PBXProject.GetPBXProjectPath(buildPath), buildPath + "/" + entitlementsPath, PBXProject.GetUnityTargetName()); capabilities.AddPushNotifications(development); capabilities.WriteToFile(); }
public static void OnPostprocessBuild(BuildTarget buildTarget, string path) { if (buildTarget != BuildTarget.iOS) { return; } UnityEngine.Debug.Log("OnPostprocessBuild"); string projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj"; PBXProject proj = new PBXProject(); proj.ReadFromString(File.ReadAllText(projPath)); string targetGuid = proj.GetUnityMainTargetGuid(); #if UNITY_2019_3_OR_NEWER pcm = new ProjectCapabilityManager(projPath, "ntsdk.entitlements", null, proj.GetUnityMainTargetGuid()); #else pcm = new ProjectCapabilityManager(projPath, "ntsdk.entitlements", PBXProject.GetUnityTargetName()); #endif #if UNITY_2019_3_OR_NEWER string target = proj.GetUnityMainTargetGuid(); #else string target = proj.TargetGuidByName("Unity-iPhone"); #endif string[] linkerFlagsToAdd = { // "-lz" , AppGuard 용 . NTSDK 에서 이미 하므로 생략함. "-lstdc++" // AppGuard 용 }; proj.UpdateBuildProperty(target, "OTHER_LDFLAGS", linkerFlagsToAdd, null); pcm.WriteToFile(); string finalFolderName = "iosConfig_Line.IcarusEternal.KR.iOS"; string configDir = Path.GetDirectoryName(Application.dataPath) + $@"/AppGuard_iOS/{finalFolderName}"; ////////////////// proj.ReadFromString(File.ReadAllText(projPath)); List <string> resources = new List <string>(); CopyAndReplaceDirectory(configDir, Path.Combine(path, finalFolderName)); GetDirFileList(configDir, ref resources, finalFolderName); foreach (string resource in resources) { Debug.Log("CopyTo 'Copy Bundle Resource' : " + resource); string resourcesBuildPhase = proj.GetResourcesBuildPhaseByTarget(targetGuid); string resourcesFilesGuid = proj.AddFile(resource, resource, PBXSourceTree.Source); proj.AddFileToBuildSection(targetGuid, resourcesBuildPhase, resourcesFilesGuid); } File.WriteAllText(projPath, proj.WriteToString()); }
protected override void Process(BuildTarget buildTarget, string buildPath) { ProjectCapabilityManager capabilities = new ProjectCapabilityManager(PBXProject.GetPBXProjectPath(buildPath), entitlementsPath, PBXProject.GetUnityTargetName()); System.Array.ForEach(modes, delegate(BackgroundModesOptions modesOptions) { capabilities.AddBackgroundModes(modesOptions); }); capabilities.WriteToFile(); }
static void AddInAppPurchasingCapability(string projPath, PBXProject proj) { var manager = new ProjectCapabilityManager( projPath, null, targetGuid: proj.GetUnityMainTargetGuid() ); manager.AddInAppPurchase(); manager.WriteToFile(); }
public void AddInAppPurchaseWorks() { SetupTestProject(); ResetGuidGenerator(); var capManager = new ProjectCapabilityManager(PBXProject.GetPBXProjectPath(GetTestOutputPath()), "test.entitlements", PBXProject.GetUnityTargetName()); capManager.AddInAppPurchase(); capManager.WriteToFile(); TestOutputProject(capManager.project, "add_iap.pbxproj"); }
void PostprocessFortvOSiOS(string path) { // Read in the Xcode project var projPath = PBXProject.GetPBXProjectPath(path); PBXProject proj = new PBXProject(); proj.ReadFromFile(projPath); // Get the main target GUID #if UNITY_2019_3_OR_NEWER var mainTarget = proj.GetUnityMainTargetGuid(); #else var mainTarget = proj.TargetGuidByName("Unity-iPhone"); #endif var entitlementsFile = $"{Application.productName}.entitlements"; string entitlementsFileName = proj.GetBuildPropertyForAnyConfig(new [] { mainTarget }, "CODE_SIGN_ENTITLEMENTS"); // If the project has an entitlements file path set, use it if (entitlementsFileName != null) { entitlementsFile = entitlementsFileName; string[] entitlementsFiles = Directory.GetFiles(path, Path.GetFileName(entitlementsFileName), SearchOption.AllDirectories); // If that file exists and we're appending the build then copy it to the staging area // so we can save the existing entitlements if (entitlementsFiles.Length > 0) { entitlementsFile = entitlementsFileName; } } #if UNITY_2019_3_OR_NEWER // AuthenticationServices should be added to the Framework target on Unity 2019.3+ proj.AddFrameworkToProject(proj.GetUnityFrameworkTargetGuid(), "AuthenticationServices.framework", false); proj.WriteToFile(projPath); // Finally add the capability and entitlement to the project // Note: The function AddSignInWithApple was added in 2018.4.12f1, 2019.2.11f1 and 2019.3.0. // If you see an error make sure that your editor version is at or above one of those versions. var capManager = new ProjectCapabilityManager(projPath, entitlementsFile, targetGuid: mainTarget); #else var capManager = new ProjectCapabilityManager(projPath, entitlementsFile, "Unity-iPhone"); #endif capManager.AddSignInWithApple(); capManager.WriteToFile(); }
public void AddWirelessAccessoryConfigurationWorks() { SetupTestProject(); ResetGuidGenerator(); var capManager = new ProjectCapabilityManager(PBXProject.GetPBXProjectPath(GetTestOutputPath()), "test.entitlements", PBXProject.GetUnityTargetName()); capManager.AddWirelessAccessoryConfiguration(); capManager.WriteToFile(); TestOutputProject(capManager.project, "add_wirelessaccessory.pbxproj"); TestOutput("test.entitlements", "add_wirelessaccessory.entitlements"); }
private static void AddCapability(string projPath) { string targetName = PBXProject.GetUnityTargetName(); var postfix = ReleaseConfig.iOS.GetValue(ReleaseConfig.iOS.KeyDefine.BundlePostfix); ProjectCapabilityManager capManager = new ProjectCapabilityManager(projPath, postfix + ".entitlements", targetName); capManager.AddBackgroundModes(BackgroundModesOptions.BackgroundFetch | BackgroundModesOptions.RemoteNotifications); capManager.AddPushNotifications(true); capManager.AddInAppPurchase(); capManager.WriteToFile(); }
public void AddDataProtectionWorks() { SetupTestProject(); ResetGuidGenerator(); var capManager = new ProjectCapabilityManager(PBXProject.GetPBXProjectPath(GetTestOutputPath()), "test.entitlements", PBXProject.GetUnityTargetName()); capManager.AddDataProtection(); capManager.WriteToFile(); TestOutputProject(capManager.project, "add_dataprotection.pbxproj"); TestOutput("test.entitlements", "add_dataprotection.entitlements"); }
public void AddAppGroupsWorks() { SetupTestProject(); ResetGuidGenerator(); var capManager = new ProjectCapabilityManager(PBXProject.GetPBXProjectPath(GetTestOutputPath()), "test.entitlements", PBXProject.GetUnityTargetName()); capManager.AddAppGroups(new string[] { "test1", "test2" }); capManager.WriteToFile(); TestOutputProject(capManager.project, "add_appgroups.pbxproj"); TestOutput("test.entitlements", "add_appgroups.entitlements"); }
public void AddBackgroundModesWorks() { SetupTestProject(); ResetGuidGenerator(); var capManager = new ProjectCapabilityManager(PBXProject.GetPBXProjectPath(GetTestOutputPath()), "test.entitlements", PBXProject.GetUnityTargetName()); capManager.AddBackgroundModes(BackgroundModesOptions.BackgroundFetch); capManager.WriteToFile(); TestOutputProject(capManager.project, "add_backgroundmodes.pbxproj"); TestOutput("Info.plist", "add_backgroundmodes.plist"); }
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"); }
public void AddMapsWorks() { SetupTestProject(); ResetGuidGenerator(); var capManager = new ProjectCapabilityManager(PBXProject.GetPBXProjectPath(GetTestOutputPath()), "test.entitlements", PBXProject.GetUnityTargetName()); capManager.AddMaps(MapsOptions.Airplane); capManager.WriteToFile(); TestOutputProject(capManager.project, "add_maps.pbxproj"); TestOutput("Info.plist", "add_maps.plist"); }
public void AddiCloudAllCustom() { SetupTestProject(); ResetGuidGenerator(); var capManager = new ProjectCapabilityManager(PBXProject.GetPBXProjectPath(GetTestOutputPath()), "test.entitlements", PBXProject.GetUnityTargetName()); capManager.AddiCloud(true, true, true, true, new string[] { "iCloud.custom.container.$(CFBundleIdentifier)" }); capManager.WriteToFile(); TestOutputProject(capManager.project, "add_icloud_cloudkit.pbxproj"); TestOutput("test.entitlements", "add_icloud_all_custom.entitlements"); }
public void AddiCloudCloudKitWorks() { SetupTestProject(); ResetGuidGenerator(); var capManager = new ProjectCapabilityManager(PBXProject.GetPBXProjectPath(GetTestOutputPath()), "test.entitlements", PBXProject.GetUnityTargetName()); capManager.AddiCloud(false, false, true, true, new string[] { }); capManager.WriteToFile(); TestOutputProject(capManager.project, "add_icloud_cloudkit.pbxproj"); TestOutput("test.entitlements", "add_icloud_cloudkit.entitlements"); }
private static void AddPushCapability(PBXProject project, string path, string targetGUID, string targetName) { var projectPath = PBXProject.GetPBXProjectPath(path); project.AddCapability(targetGUID, PBXCapabilityType.PushNotifications); project.AddCapability(targetGUID, PBXCapabilityType.BackgroundModes); var entitlementsPath = GetEntitlementsPath(path, project, targetGUID, targetName); // NOTE: ProjectCapabilityManager's 4th constructor param requires Unity 2019.3+ var projCapability = new ProjectCapabilityManager(projectPath, entitlementsPath, targetName); projCapability.AddBackgroundModes(BackgroundModesOptions.RemoteNotifications); projCapability.WriteToFile(); }
public void AddHealthKitWorks() { SetupTestProject(); ResetGuidGenerator(); var capManager = new ProjectCapabilityManager(PBXProject.GetPBXProjectPath(GetTestOutputPath()), "test.entitlements", PBXProject.GetUnityTargetName()); capManager.AddHealthKit(); capManager.WriteToFile(); TestOutputProject(capManager.project, "add_healthkit.pbxproj"); TestOutput("test.entitlements", "add_healthkit.entitlements"); TestOutput("Info.plist", "add_healthkit.plist"); }
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); } } }
/// <summary> /// Add the required capabilities and entitlements for OneSignal /// </summary> private void AddProjectCapabilities() { var targetGuid = _project.GetMainTargetGuid(); var targetName = _project.GetMainTargetName(); var entitlementsPath = GetEntitlementsPath(targetGuid, targetName); var projCapability = new ProjectCapabilityManager(_projectPath, entitlementsPath, targetName); projCapability.AddBackgroundModes(BackgroundModesOptions.RemoteNotifications); projCapability.AddPushNotifications(false); projCapability.AddAppGroups(new[] { _appGroupName }); projCapability.WriteToFile(); }
public void AddMultipleCapabilitiesWorks() { SetupTestProject(); ResetGuidGenerator(); var capManager = new ProjectCapabilityManager(PBXProject.GetPBXProjectPath(GetTestOutputPath()), "test.entitlements", PBXProject.GetUnityTargetName()); capManager.AddGameCenter(); capManager.AddInAppPurchase(); capManager.AddMaps(MapsOptions.Airplane); capManager.WriteToFile(); TestOutputProject(capManager.project, "add_multiple.pbxproj"); }
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(); }
public void AddMultipleCapabilitiesWithEntitlementWorks() { SetupTestProject(); ResetGuidGenerator(); var capManager = new ProjectCapabilityManager(PBXProject.GetPBXProjectPath(GetTestOutputPath()), "test.entitlements", PBXProject.GetUnityTargetName()); capManager.AddiCloud(true, false, false, true, new string[] {}); capManager.AddApplePay(new string[] { "test1", "test2" }); capManager.AddSiri(); capManager.WriteToFile(); TestOutputProject(capManager.project, "add_multiple_entitlements.pbxproj"); TestOutput("test.entitlements", "add_multiple_entitlements.entitlements"); }
/// <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(); }