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 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(); }
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"); }
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"); }
static void AddCapabilities(PBXProject proj, string targetGuid, ProjectCapabilityManager capManager) { if (ISD_Settings.Instance.Capabilities.Count == 0) { return; } foreach (var cap in ISD_Settings.Instance.Capabilities) { switch (cap.CapabilityType) { case ISD_CapabilityType.Cloud: var cloudSettings = ISD_Settings.Instance.iCloudCapabilitySettings; capManager.AddiCloud(cloudSettings.KeyValueStorage, cloudSettings.iCloudDocument, new string[] { }); break; 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; } } }
public static void OnPostprocessBuild(BuildTarget target, string buildPath) { // Add declared custom types to Info.plist if (target == BuildTarget.iOS) { NativeFilePickerCustomTypes.TypeHolder[] customTypes = NativeFilePickerCustomTypes.GetCustomTypes(); if (customTypes != null) { string plistPath = Path.Combine(buildPath, "Info.plist"); PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); PlistElementDict rootDict = plist.root; for (int i = 0; i < customTypes.Length; i++) { NativeFilePickerCustomTypes.TypeHolder customType = customTypes[i]; PlistElementArray customTypesArray = GetCustomTypesArray(rootDict, customType.isExported); // Don't allow duplicate entries RemoveCustomTypeIfExists(customTypesArray, customType.identifier); PlistElementDict customTypeDict = customTypesArray.AddDict(); customTypeDict.SetString("UTTypeIdentifier", customType.identifier); customTypeDict.SetString("UTTypeDescription", customType.description); PlistElementArray conformsTo = customTypeDict.CreateArray("UTTypeConformsTo"); for (int j = 0; j < customType.conformsTo.Length; j++) { conformsTo.AddString(customType.conformsTo[j]); } PlistElementDict tagSpecification = customTypeDict.CreateDict("UTTypeTagSpecification"); PlistElementArray tagExtensions = tagSpecification.CreateArray("public.filename-extension"); for (int j = 0; j < customType.extensions.Length; j++) { tagExtensions.AddString(customType.extensions[j]); } } File.WriteAllText(plistPath, plist.WriteToString()); } } // Rest of the function shouldn't execute unless build post-processing is enabled if (!AUTO_SETUP_FRAMEWORKS && !AUTO_SETUP_ICLOUD) { return; } if (target == BuildTarget.iOS) { string pbxProjectPath = PBXProject.GetPBXProjectPath(buildPath); PBXProject pbxProject = new PBXProject(); pbxProject.ReadFromFile(pbxProjectPath); #if UNITY_2019_3_OR_NEWER string targetGUID = pbxProject.GetUnityFrameworkTargetGuid(); #else string targetGUID = pbxProject.TargetGuidByName(PBXProject.GetUnityTargetName()); #endif if (AUTO_SETUP_FRAMEWORKS) { pbxProject.AddBuildProperty(targetGUID, "OTHER_LDFLAGS", "-framework MobileCoreServices"); pbxProject.AddBuildProperty(targetGUID, "OTHER_LDFLAGS", "-framework CloudKit"); } #if !UNITY_2017_1_OR_NEWER if (AUTO_SETUP_ICLOUD) { // Add iCloud capability without Cloud Build support on 5.6 or earlier string entitlementsPath = Path.Combine(buildPath, "iCloud.entitlements"); File.WriteAllText(entitlementsPath, ICLOUD_ENTITLEMENTS); pbxProject.AddFile(entitlementsPath, Path.GetFileName(entitlementsPath)); pbxProject.AddBuildProperty(targetGUID, "CODE_SIGN_ENTITLEMENTS", entitlementsPath); } #endif File.WriteAllText(pbxProjectPath, pbxProject.WriteToString()); #if UNITY_2017_1_OR_NEWER if (AUTO_SETUP_ICLOUD) { // Add iCloud capability with Cloud Build support on 2017.1+ #if UNITY_2019_3_OR_NEWER ProjectCapabilityManager manager = new ProjectCapabilityManager(pbxProjectPath, "iCloud.entitlements", "Unity-iPhone"); #else ProjectCapabilityManager manager = new ProjectCapabilityManager(pbxProjectPath, "iCloud.entitlements", PBXProject.GetUnityTargetName()); #endif #if UNITY_2018_3_OR_NEWER manager.AddiCloud(false, true, false, true, null); #else manager.AddiCloud(false, true, true, null); #endif manager.WriteToFile(); } #endif } }
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 PostProcessXCodeProject(string path) { Debug.Log("Post Process X Code Project"); var settings = GetBuildSettings(); if (settings.EnablePostProcessXCodeProject == false) { Debug.Log("[HovelHouse.CloudKit] skipping post process build step..."); return; } Debug.Log("[HovelHouse.CloudKit] " + path); // When building a MacOS xCode project, unity's GetPBXProjectPath // returns the wrong pbxproject path #if UNITY_STANDALONE_OSX && UNITY_2019_3_OR_NEWER string pbxPath = Path.Combine(path, "./project.pbxproj"); #else string pbxPath = PBXProject.GetPBXProjectPath(path); #endif var pbxProject = new PBXProject(); pbxProject.ReadFromFile(pbxPath); var name = PlayerSettings.applicationIdentifier.Split('.').Last(); #if UNITY_2019_3_OR_NEWER // On MacOS GetUnityManTargetGuid returns null - so we have to look it up by name // but honestly, doesn't even look like the ProjectCapabilityManager is doing anything // on MacOS #if UNITY_STANDALONE_OSX string targetGUID = pbxProject.TargetGuidByName(name); string entitlementsFilename = name + "/" + name + ".entitlements"; #else string targetGUID = pbxProject.GetUnityMainTargetGuid(); string entitlementsFilename = name + ".entitlements"; #endif if (string.IsNullOrEmpty(targetGUID)) { throw new BuildFailedException("unable to find the GUID of the build target"); } ProjectCapabilityManager projCapability = new ProjectCapabilityManager( pbxPath, entitlementsFilename, null, targetGUID); #else string entitlementsFilename = name + ".entitlements"; ProjectCapabilityManager projCapability = new ProjectCapabilityManager( pbxPath, entitlementsFilename, PBXProject.GetUnityTargetName()); #endif projCapability.AddiCloud( settings.EnableKeyVaueStorage, settings.EnableDocumentStorage, settings.EnableCloudKit, settings.AddDefaultContainers, settings.CustomContainers); if (settings.EnableCloudKitNotifications) { projCapability.AddPushNotifications(settings.apsEnvironment == APSEnvironment.Development); projCapability.AddBackgroundModes((BackgroundModesOptions)settings.BackgroundModes); } projCapability.WriteToFile(); }
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(); } }