private static void TrySetCapabilityiesWithOptionsInXcode(string buildPath, string entitlementsName) { string pbxPath = PBXProject.GetPBXProjectPath(buildPath); PBXProject pbxProject = new PBXProject(); pbxProject.ReadFromFile(pbxPath); var target_name = PBXProject.GetUnityTargetName(); var target_guid = pbxProject.TargetGuidByName(target_name); UnityEditor.iOS.Xcode.PBXCapabilityType typeTOadd = PBXCapabilityType.InAppPurchase; bool isAddeded = pbxProject.AddCapability(target_guid, typeTOadd, entitlementsName, true); if (!isAddeded) { Debug.LogError(" Failed to Add : " + typeTOadd.ToString()); } typeTOadd = PBXCapabilityType.PushNotifications; isAddeded = pbxProject.AddCapability(target_guid, typeTOadd, entitlementsName, true); if (!isAddeded) { Debug.LogError(" Failed to Add : " + typeTOadd.ToString()); } typeTOadd = PBXCapabilityType.BackgroundModes; isAddeded = pbxProject.AddCapability(target_guid, typeTOadd, entitlementsName, true); if (!isAddeded) { Debug.LogError(" Failed to Add : " + typeTOadd.ToString()); } File.WriteAllText(pbxPath, pbxProject.WriteToString()); }
// Allow user to add a Capability public bool AddCapability(string targetGuid, PBXCapabilityType capability, string entitlementsFilePath = null, bool addOptionalFramework = false) { // If the capability requires entitlements then you have to provide the name of it or we don't add the capability. if (capability.requiresEntitlements && entitlementsFilePath == "") { throw new Exception("Couldn't add the Xcode Capability " + capability.id + " to the PBXProject file because this capability requires an entitlement file."); } var p = project.project; // If an entitlement with a different name was added for another capability // we don't add this capacity. if (p.entitlementsFile != null && entitlementsFilePath != null && p.entitlementsFile != entitlementsFilePath) { if (p.capabilities.Count > 0) { throw new WarningException("Attention, it seems that you have multiple entitlements file. Only one will be added the Project : " + p.entitlementsFile); } return(false); } // Add the capability only if it doesn't already exist. if (p.capabilities.Contains(new PBXCapabilityType.TargetCapabilityPair(targetGuid, capability))) { throw new WarningException("This capability has already been added. Method ignored"); } p.capabilities.Add(new PBXCapabilityType.TargetCapabilityPair(targetGuid, capability)); // Add the required framework. if (capability.framework != "" && !capability.optionalFramework || (capability.framework != "" && capability.optionalFramework && addOptionalFramework)) { AddFrameworkToProject(targetGuid, capability.framework, false); } // Finally add the entitlement code signing if it wasn't added before. if (entitlementsFilePath != null && p.entitlementsFile == null) { p.entitlementsFile = entitlementsFilePath; AddFileImpl(entitlementsFilePath, entitlementsFilePath, PBXSourceTree.Source, false); SetBuildProperty(targetGuid, "CODE_SIGN_ENTITLEMENTS", PBXPath.FixSlashes(entitlementsFilePath)); } return(true); }
public TargetCapabilityPair(string guid, PBXCapabilityType type) { this.targetGuid = guid; this.capability = type; }