void PostprocessForMacOS(string path) { // Read in the Xcode project var projPath = Path.Combine(path, "project.pbxproj"); PBXProject proj = new PBXProject(); proj.ReadFromFile(projPath); // Get the main target GUID var mainTarget = proj.TargetGuidByName(Application.productName); 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 proj.AddFrameworkToProject(mainTarget, "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, Application.productName); #endif capManager.AddSignInWithApple(); capManager.WriteToFile(); }
private static void AddCapability(MOBXCodeEditorModel xcodeModel, PBXProject xcodeProj, string xcodeTargetGuid, string xcodeTargetPath) { string projectPath = PBXProject.GetPBXProjectPath(xcodeTargetPath); if (xcodeModel.isOpenRestoreScene || xcodeModel.isHaveApple || xcodeModel.associatedDomains.Count > 0) { 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 void OnPostprocessBuild(BuildReport report) { // Clean and reset settings after builds to make sure we don't // pollute later builds with assets that may be unnecessary or are outdated. CleanOldSettings(); #if (UNITY_IOS || UNITY_TVOS) && UNITY_2019_2 PBXProject proj = new PBXProject(); string pbxFilename = report.summary.outputPath + "/Unity-iPhone.xcodeproj/project.pbxproj"; proj.ReadFromFile(pbxFilename); var targetName = PBXProject.GetUnityTargetName(); var targetBuild = proj.TargetGuidByName(name: targetName); proj.AddFrameworkToProject(targetBuild, "AuthenticationServices.framework", false); proj.WriteToFile(pbxFilename); #endif #if (UNITY_IOS || UNITY_TVOS) && UNITY_2019_3_OR_NEWER PBXProject proj = new PBXProject(); string pbxFilename = report.summary.outputPath + "/Unity-iPhone.xcodeproj/project.pbxproj"; proj.ReadFromFile(pbxFilename); // The framework needs to be on the framework target rather than the main target as the capability manager does string frameworkTarget = proj.GetUnityFrameworkTargetGuid(); proj.AddFrameworkToProject(frameworkTarget, "AuthenticationServices.framework", false); string mainTarget = proj.GetUnityMainTargetGuid(); // Check if the project has an existing entitlements file path set string entitlementsFileName = proj.GetBuildPropertyForAnyConfig(mainTarget, "CODE_SIGN_ENTITLEMENTS"); if (entitlementsFileName == null) { entitlementsFileName = report.summary.outputPath + string.Format("/{0}.entitlements", PlayerSettings.productName); } proj.WriteToFile(pbxFilename); var identitySettings = GetPlayerIdentityGeneralSettings(EditorUserBuildSettings.selectedBuildTargetGroup); var appleLoaderExists = identitySettings?.Manager?.providerLoaders?.Exists(x => x.GetType() == typeof(AppleLoader)); if (appleLoaderExists == null || !(bool)appleLoaderExists) { return; } var capManager = new ProjectCapabilityManager(pbxFilename, entitlementsFileName, targetGuid: mainTarget); capManager.AddSignInWithApple(); capManager.WriteToFile(); #endif }
private static void AddAppGroup(string buildPath, string appGroup) { string projectPath = PBXProject.GetPBXProjectPath(buildPath); var project = new PBXProject(); project.ReadFromString(File.ReadAllText(projectPath)); #if UNITY_2019_3_OR_NEWER string targetGuid = project.GetUnityMainTargetGuid(); var manager = new ProjectCapabilityManager(projectPath, "Entitlements.entitlements", null, targetGuid); #else string targetGuid = project.TargetGuidByName("Unity-iPhone"); var manager = new ProjectCapabilityManager(projectPath, "Entitlements.entitlements", targetGuid); #endif manager.AddAppGroups(new string[] { appGroup }); manager.WriteToFile(); }
private static void OnPostProcessBuild(BuildTarget buildTarget, string path) { if (buildTarget == BuildTarget.iOS) { _path = path; AddFramework(); AddInfoPlist(); var projCapability = new ProjectCapabilityManager(_projPath, "Unity-iPhone/mmk.entitlements", "Unity-iPhone"); projCapability.AddBackgroundModes(BackgroundModesOptions.RemoteNotifications); projCapability.AddPushNotifications(Debug.isDebugBuild); projCapability.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();//写入文件保存 }
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; } } }
/// <summary> /// Create and add the notification extension to the project /// </summary> private void AddNotificationServiceExtension() { #if !UNITY_CLOUD_BUILD // refresh plist and podfile on appends ExtensionCreatePlist(_outputPath); ExtensionAddPodsToTarget(); var extensionGuid = _project.TargetGuidByName(ServiceExtensionTargetName); // skip target setup if already present if (!string.IsNullOrEmpty(extensionGuid)) { return; } extensionGuid = _project.AddAppExtension(_project.GetMainTargetGuid(), ServiceExtensionTargetName, PlayerSettings.GetApplicationIdentifier(BuildTargetGroup.iOS) + "." + ServiceExtensionTargetName, ServiceExtensionTargetName + "/" + "Info.plist" // Unix path as it's used by Xcode ); ExtensionAddSourceFiles(extensionGuid); // Makes it so that the extension target is Universal (not just iPhone) and has an iOS 10 deployment target _project.SetBuildProperty(extensionGuid, "TARGETED_DEVICE_FAMILY", "1,2"); _project.SetBuildProperty(extensionGuid, "IPHONEOS_DEPLOYMENT_TARGET", "10.0"); _project.SetBuildProperty(extensionGuid, "SWIFT_VERSION", "5.0"); _project.SetBuildProperty(extensionGuid, "ARCHS", "arm64"); _project.SetBuildProperty(extensionGuid, "DEVELOPMENT_TEAM", PlayerSettings.iOS.appleDeveloperTeamID); _project.AddBuildProperty(extensionGuid, "LIBRARY_SEARCH_PATHS", $"$(PROJECT_DIR)/Libraries/{PluginLibrariesPath.Replace("\\", "/")}"); _project.WriteToFile(_projectPath); // add capabilities + entitlements var entitlementsPath = GetEntitlementsPath(extensionGuid, ServiceExtensionTargetName); var projCapability = new ProjectCapabilityManager(_projectPath, entitlementsPath, ServiceExtensionTargetName); projCapability.AddAppGroups(new[] { _appGroupName }); projCapability.WriteToFile(); #endif }
/// <summary> /// Extension method for ProjectCapabilityManager to add the Sign In With Apple capability in compatibility mode. /// In particular, adds the AuthenticationServices.framework as an Optional framework, preventing crashes in /// iOS versions previous to 13.0 /// </summary> /// <param name="manager">The manager for the main target to use when adding the Sign In With Apple capability.</param> /// <param name="unityFrameworkTargetGuid">The GUID for the UnityFramework target. If null, it will use the main target GUID.</param> public static void AddSignInWithAppleWithCompatibility(this ProjectCapabilityManager manager, string unityFrameworkTargetGuid = null) { 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 entitlementFilePath = entitlementFilePathField.GetValue(manager) as string; var entitlementDoc = getOrCreateEntitlementDocMethod.Invoke(manager, new object[] { }) as PlistDocument; if (entitlementDoc != null) { var plistArray = new PlistElementArray(); plistArray.AddString(DefaultAccessLevel); entitlementDoc.root[EntitlementsArrayKey] = plistArray; } var project = projectField.GetValue(manager) as PBXProject; if (project != null) { var mainTargetGuid = targetGuidField.GetValue(manager) as string; var capabilityType = constructorInfo.Invoke(new object[] { "com.apple.developer.applesignin.custom", true, string.Empty, true }) as PBXCapabilityType; var targetGuidToAddFramework = unityFrameworkTargetGuid ?? mainTargetGuid; project.AddFrameworkToProject(targetGuidToAddFramework, AuthenticationServicesFramework, true); project.AddCapability(mainTargetGuid, capabilityType, entitlementFilePath, false); } }
public static void OnPostProcessBuild(BuildTarget target, string path) { if (target != BuildTarget.iOS) { return; } var projectPath = PBXProject.GetPBXProjectPath(path); #if UNITY_2019_3_OR_NEWER var project = new PBXProject(); project.ReadFromString(System.IO.File.ReadAllText(projectPath)); var manager = new ProjectCapabilityManager(projectPath, "Entitlements.entitlements", targetGuid: project.GetUnityMainTargetGuid()); #else var manager = new ProjectCapabilityManager(projectPath, "Entitlements.entitlements", PBXProject.GetUnityTargetName()); #endif manager.AddSignInWithApple(); manager.WriteToFile(); }
private static void SetCapabilitiesSimple(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); var capManager = new ProjectCapabilityManager(pbxPath, entitlementsName, target_name); capManager.AddGameCenter(); capManager.AddInAppPurchase(); bool developmentMode = true; // Development mode should be used while testing your application outside of the App Store. capManager.AddPushNotifications(developmentMode); capManager.AddBackgroundModes(BackgroundModesOptions.RemoteNotifications); //todo: Problem is: is not setting up remote notification flag capManager.WriteToFile(); // will update Info List, Will update Capability Entitlements }
/// <summary> /// 修改pbxproj文件 /// </summary> private void ModifyPbxproj() { var pbxprojPath = PBXProject.GetPBXProjectPath(pathToBuiltProject); var pbxProject = new PBXProject(); pbxProject.ReadFromFile(pbxprojPath); var frameworkTarget = pbxProject.GetUnityFrameworkTargetGuid(); if (!config.ios.bitCode) { CloseBitCode(pbxProject, frameworkTarget); } var prejectTarget = pbxProject.GetUnityMainTargetGuid(); pbxProject.AddCapability(prejectTarget, PBXCapabilityType.InAppPurchase, "ios.entitlements"); var capManager = new ProjectCapabilityManager(pbxprojPath, "ios.entitlements", null, prejectTarget); AddCapability(capManager); pbxProject.WriteToFile(pbxprojPath); }
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(); }
//----- method ----- protected void UpdatePbxProj(BuildTarget buildTarget, string path) { if (buildTarget != BuildTarget.iOS) { return; } try { PbxProj = new PBXProject(); var projectPath = PBXProject.GetPBXProjectPath(path); PbxProj.ReadFromString(File.ReadAllText(projectPath)); #if UNITY_2020_2_OR_NEWER TargetGuid = PbxProj.GetUnityMainTargetGuid(); #else TargetGuid = PbxProj.TargetGuidByName("Unity-iPhone"); #endif CapabilityManager = new ProjectCapabilityManager(projectPath, EntitlementFileName, null, TargetGuid); EditPbxProj(); CapabilityManager.WriteToFile(); File.WriteAllText(projectPath, PbxProj.WriteToString()); PbxProj = null; CapabilityManager = null; TargetGuid = null; } catch (Exception e) { Debug.LogException(e); } }
public static void OnPostprocessBuildHandler(BuildTarget buildTarget, string path) { var projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj"; var proj = new PBXProject(); proj.ReadFromString(File.ReadAllText(projPath)); var target = proj.GetUnityMainTargetGuid(); proj.AddFrameworkToProject(target, "UserNotifications.framework", true); proj.AddCapability(target, PBXCapabilityType.PushNotifications); if (Directory.Exists(ICONS_PROJECT_PATH)) { foreach (var file in Directory.GetFiles(ICONS_PROJECT_PATH, "*.png", SearchOption.AllDirectories)) { var dstLocalPath = Path.GetFileName(file); var resourcesBuildPhase = proj.GetResourcesBuildPhaseByTarget(target); var fileRef = proj.AddFile(dstLocalPath, dstLocalPath); File.Copy(file, Path.Combine(path, dstLocalPath), true); proj.AddFileToBuild(target, fileRef); } } File.WriteAllText(projPath, proj.WriteToString()); var capabilities = new ProjectCapabilityManager(PBXProject.GetPBXProjectPath(path), "app.entitlements", "Unity-iPhone"); capabilities.AddPushNotifications(true); capabilities.AddBackgroundModes(BackgroundModesOptions.RemoteNotifications); capabilities.WriteToFile(); }
private static void AddCapabilities(PBXProject project, string pathToBuildProject) { string targetGuid = project.GetUnityMainTargetGuid(); string relativeEntitlementsFilePath = ProductName + "." + "entitlements"; ProjectCapabilityManager manager = new ProjectCapabilityManager(pathToBuildProject + "/Unity-iPhone.xcodeproj/project.pbxproj", relativeEntitlementsFilePath, "Unity-iPhone"); // 1. game center manager.AddGameCenter(); if (project.ContainsFramework(targetGuid, "GameKit.framework") == false) { Debug.Log("Add GameKit.framework"); project.AddFrameworkToProject(targetGuid, "GameKit.framework", true); } // 2. purchase manager.AddInAppPurchase(); if (project.ContainsFramework(targetGuid, "StoreKit.framework") == false) { Debug.Log("Add StoreKit.framework"); project.AddFrameworkToProject(targetGuid, "StoreKit.framework", true); } // 3. remote push manager.AddPushNotifications(true); project.AddFile(relativeEntitlementsFilePath, relativeEntitlementsFilePath); project.AddBuildProperty(targetGuid, "CODE_SIGN_ENTITLEMENTS", relativeEntitlementsFilePath); // 4. background manager.AddBackgroundModes(BackgroundModesOptions.RemoteNotifications); // 4. domains //string[] domains = { "xxx"}; //manager.AddAssociatedDomains(domains); manager.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()); } }
public static void OnPostProcessBuild(BuildTarget target, string path) { if (target == BuildTarget.iOS || target == BuildTarget.tvOS) { #if UNITY_XCODE_EXTENSIONS_AVAILABLE var projectPath = PBXProject.GetPBXProjectPath(path); #if UNITY_2019_3_OR_NEWER var project = new PBXProject(); project.ReadFromString(System.IO.File.ReadAllText(projectPath)); var manager = new ProjectCapabilityManager(projectPath, "Entitlements.entitlements", null, project.GetUnityMainTargetGuid()); manager.AddSignInWithAppleWithCompatibility(project.GetUnityFrameworkTargetGuid()); manager.WriteToFile(); #else var manager = new ProjectCapabilityManager(projectPath, "Entitlements.entitlements", PBXProject.GetUnityTargetName()); manager.AddSignInWithAppleWithCompatibility(); manager.WriteToFile(); #endif #endif } else if (target == BuildTarget.StandaloneOSX) { AppleAuthMacosPostprocessorHelper.FixManagerBundleIdentifier(target, path); } }
/// <summary> /// Enables the "Access Wi-Fi Information" capability for the Unity player target /// </summary> /// <param name="buildOutputPath">Build output path.</param> private static void EnableAccessWifiInformationCapability(string buildOutputPath) { #if UNITY_IOS string xcodeProjectFolder = "Unity-iPhone.xcodeproj"; string pbxProjectPath = Path.Combine(buildOutputPath, xcodeProjectFolder, "project.pbxproj"); string entitlementsPath = Path.Combine(xcodeProjectFolder, "helloar.entitlements"); string unityPlayerTarget = "Unity-iPhone"; ProjectCapabilityManager capabilityManager = new ProjectCapabilityManager(pbxProjectPath, entitlementsPath, unityPlayerTarget); capabilityManager.AddAccessWiFiInformation(); capabilityManager.WriteToFile(); string accessWifiInformationCapabilityName = "com.apple.AccessWiFi"; if (!accessWifiInformationCapabilityName.Equals(PBXCapabilityType.AccessWiFiInformation.id)) { Debug.LogWarning($"Working around Unity bug: " + $"PBXCapabilityType.AccessWiFiInformation.id should be {accessWifiInformationCapabilityName} " + $"but is {PBXCapabilityType.AccessWiFiInformation.id} instead."); string oldProject = File.ReadAllText(pbxProjectPath); string newProject = oldProject.Replace(PBXCapabilityType.AccessWiFiInformation.id, accessWifiInformationCapabilityName); File.WriteAllText(pbxProjectPath, newProject); } #endif }
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 } }
public static void OnPostprocessBuild(BuildTarget target, string projectPath) { var pbxProjPath = PBXProject.GetPBXProjectPath(projectPath); PBXProject proj = new PBXProject(); proj.ReadFromFile(pbxProjPath); string targetGuid = proj.TargetGuidByName("Unity-iPhone"); RegisterAppLanguages(); AddFlags(proj, targetGuid); AddLibraries(proj, targetGuid); AddFrameworks(proj, targetGuid, target); AddEmbededFrameworks(proj, targetGuid); AddPlistVariables(projectPath); ApplyBuildSettings(proj, targetGuid); CopyAssetFiles(proj, projectPath, targetGuid); AddShellScriptBuildPhase(proj, targetGuid); proj.WriteToFile(pbxProjPath); var capManager = new ProjectCapabilityManager(pbxProjPath, ISD_Settings.ENTITLEMENTS_FILE_NAME, "Unity-iPhone"); AddCapabilities(proj, targetGuid, capManager); capManager.WriteToFile(); //Some API simply does not work so on this block we are applying a workaround //after Unity deploy scrips has stopped working //Addons EmbededFrameworks foreach (var framework in ISD_Settings.Instance.EmbededFrameworks) { string contents = File.ReadAllText(pbxProjPath); string pattern = "(?<=Embed Frameworks)(?:.*)(\\/\\* " + framework.FileName + "\\ \\*\\/)(?=; };)"; string oldText = "/* " + framework.FileName + " */"; string updatedText = "/* " + framework.FileName + " */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }"; contents = Regex.Replace(contents, pattern, m => m.Value.Replace(oldText, updatedText)); File.WriteAllText(pbxProjPath, contents); } var entitlementsPath = projectPath + "/" + ISD_Settings.ENTITLEMENTS_FILE_NAME; if (ISD_Settings.Instance.EntitlementsMode == ISD_EntitlementsGenerationMode.Automatic) { if (ISD_Settings.Instance.Capability.iCloud.Enabled) { if (ISD_Settings.Instance.Capability.iCloud.keyValueStorage && !ISD_Settings.Instance.Capability.iCloud.iCloudDocument) { var entitlements = new PlistDocument(); entitlements.ReadFromFile(entitlementsPath); var plistVariable = new PlistElementArray(); entitlements.root["com.apple.developer.icloud-container-identifiers"] = plistVariable; entitlements.WriteToFile(entitlementsPath); } } } else { if (ISD_Settings.Instance.EntitlementsFile != null) { var entitlementsContentPath = SA_AssetDatabase.GetAbsoluteAssetPath(ISD_Settings.Instance.EntitlementsFile); string contents = File.ReadAllText(entitlementsContentPath); File.WriteAllText(entitlementsPath, contents); } else { Debug.LogWarning("ISD: EntitlementsMode set to Manual but no file provided"); } } }
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; * } * } */ }
public static void OnPostprocessBuild(BuildTarget buildTarget, string path) { #if PLATFORM_IOS if (buildTarget == BuildTarget.iOS) { var projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj"; var proj = new PBXProject(); proj.ReadFromString(File.ReadAllText(projPath)); string mainTarget; string unityFrameworkTarget; var unityMainTargetGuidMethod = proj.GetType().GetMethod("GetUnityMainTargetGuid"); var unityFrameworkTargetGuidMethod = proj.GetType().GetMethod("GetUnityFrameworkTargetGuid"); if (unityMainTargetGuidMethod != null && unityFrameworkTargetGuidMethod != null) { mainTarget = (string)unityMainTargetGuidMethod.Invoke(proj, null); unityFrameworkTarget = (string)unityFrameworkTargetGuidMethod.Invoke(proj, null); } else { mainTarget = proj.TargetGuidByName("Unity-iPhone"); unityFrameworkTarget = mainTarget; } var settings = UnityNotificationEditorManager.Initialize().iOSNotificationEditorSettingsFlat; var addPushNotificationCapability = (bool)settings .Find(i => i.key == "UnityAddRemoteNotificationCapability").val == true;; var needLocationFramework = (bool)settings .Find(i => i.key == "UnityUseLocationNotificationTrigger").val == true;; proj.AddFrameworkToProject(unityFrameworkTarget, "UserNotifications.framework", true); if (needLocationFramework) { proj.AddFrameworkToProject(unityFrameworkTarget, "CoreLocation.framework", false); } File.WriteAllText(projPath, proj.WriteToString()); if (addPushNotificationCapability) { var useReleaseAPSEnvSetting = settings .Find(i => i.key == "UnityUseAPSReleaseEnvironment"); var useReleaseAPSEnv = false; if (useReleaseAPSEnvSetting != null) { useReleaseAPSEnv = (bool)useReleaseAPSEnvSetting.val; } var entitlementsFileName = proj.GetBuildPropertyForConfig(mainTarget, "CODE_SIGN_ENTITLEMENTS"); if (entitlementsFileName == null) { var bundleIdentifier = PlayerSettings.GetApplicationIdentifier(BuildTargetGroup.iOS); entitlementsFileName = string.Format("{0}.entitlements", bundleIdentifier.Substring(bundleIdentifier.LastIndexOf(".") + 1)); } var pbxPath = PBXProject.GetPBXProjectPath(path); var capManager = new ProjectCapabilityManager(pbxPath, entitlementsFileName, "Unity-iPhone"); capManager.AddPushNotifications(!useReleaseAPSEnv); capManager.WriteToFile(); } // Get plist var plistPath = path + "/Info.plist"; var plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); // Get root var rootDict = plist.root; var requiredVersion = new Version(8, 0); bool hasMinOSVersion; try { var currentVersion = new Version(PlayerSettings.iOS.targetOSVersionString); hasMinOSVersion = currentVersion >= requiredVersion; } catch (Exception) { hasMinOSVersion = false; } if (!hasMinOSVersion) { Debug.Log("UserNotifications are only available on iOSSettings 10 and above, please make sure that you set a correct `Target minimum iOSSettings Version` in Player Settings."); } foreach (var setting in settings) { if (setting.val.GetType() == typeof(bool)) { rootDict.SetBoolean(setting.key, (bool)setting.val); } else if (setting.val.GetType() == typeof(PresentationOption) || setting.val.GetType() == typeof(AuthorizationOption)) { rootDict.SetInteger(setting.key, (int)setting.val); } } if (addPushNotificationCapability) { PlistElementArray currentBacgkgroundModes = (PlistElementArray)rootDict["UIBackgroundModes"]; if (currentBacgkgroundModes == null) { currentBacgkgroundModes = rootDict.CreateArray("UIBackgroundModes"); } currentBacgkgroundModes.AddString("remote-notification"); } // Write to file File.WriteAllText(plistPath, plist.WriteToString()); //Get Preprocessor.h var preprocessorPath = path + "/Classes/Preprocessor.h"; var preprocessor = File.ReadAllText(preprocessorPath); if (needLocationFramework) { if (preprocessor.Contains("UNITY_USES_LOCATION")) { preprocessor = preprocessor.Replace("UNITY_USES_LOCATION 0", "UNITY_USES_LOCATION 1"); } } preprocessor = preprocessor.Replace("UNITY_USES_REMOTE_NOTIFICATIONS 0", "UNITY_USES_REMOTE_NOTIFICATIONS 1"); File.WriteAllText(preprocessorPath, preprocessor); } #endif }
public static void OnPostprocessBuild(BuildTarget target, string projectPath) { var pbxProjPath = PBXProject.GetPBXProjectPath(projectPath); PBXProject proj = new PBXProject(); proj.ReadFromFile(pbxProjPath); string targetGuid = proj.GetUnityMainTargetGuid();//alesta RegisterAppLanguages(); AddFlags(proj, targetGuid); AddLibraries(proj, targetGuid); AddFrameworks(proj, targetGuid); AddEmbededFrameworks(proj, targetGuid); AddPlistVariables(proj, projectPath, targetGuid); ApplyBuildSettings(proj, targetGuid); CopyAssetFiles(proj, projectPath, targetGuid); AddShellScriptBuildPhase(proj, targetGuid); proj.WriteToFile(pbxProjPath); var capManager = new ProjectCapabilityManager(pbxProjPath, ISD_Settings.ENTITLEMENTS_FILE_NAME, "Unity-iPhone"); AddCapabilities(proj, targetGuid, capManager); capManager.WriteToFile(); //Some API simply doens not work so on this block we are aplplying a workaround //after unuty deploy scrips has stoped working //Addons EmbededFrameworks foreach (var framework in ISD_Settings.Instance.EmbededFrameworks) { string contents = File.ReadAllText(pbxProjPath); string pattern = "(?<=Embed Frameworks)(?:.*)(\\/\\* " + framework.FileName + "\\ \\*\\/)(?=; };)"; string oldText = "/* " + framework.FileName + " */"; string updatedText = "/* " + framework.FileName + " */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }"; contents = Regex.Replace(contents, pattern, m => m.Value.Replace(oldText, updatedText)); File.WriteAllText(pbxProjPath, contents); } //Capatibilities foreach (var cap in ISD_Settings.Instance.Capabilities) { if (cap.CapabilityType == ISD_CapabilityType.Cloud) { var entitlements = new PlistDocument(); var infoPlistPath = projectPath + "/" + ISD_Settings.ENTITLEMENTS_FILE_NAME; entitlements.ReadFromFile(infoPlistPath); var plistVariable = new PlistElementArray(); entitlements.root["com.apple.developer.icloud-container-identifiers"] = plistVariable; entitlements.WriteToFile(infoPlistPath); } } }
protected override void OnPostProcessBuild(string playerPath) { #if UNITY_IOS string projPath = Path.Combine(playerPath, "Unity-iPhone.xcodeproj/project.pbxproj"); PBXProject proj = new PBXProject(); proj.ReadFromFile(projPath); string target = proj.TargetGuidByName("Unity-iPhone"); proj.SetBuildProperty(target, "ENABLE_BITCODE", m_EnableBitcode ? "YES" : "NO"); if (string.IsNullOrEmpty(m_AppleDeveloperTeamId)) { proj.SetBuildProperty(target, "DEVELOPMENT_TEAM", m_AppleDeveloperTeamId); } for (int i = 0; i < m_Frameworks.Length; i++) { var s = m_Frameworks[i]; proj.AddFrameworkToProject(target, s, true); } for (int i = 0; i < m_Files.Length; i++) { var s = m_Files[i]; proj.AddFileToBuild(target, proj.AddFile(Path.Combine("usr/lib/", s.Name), Path.Combine("Frameworks/", s.Name), (PBXSourceTree)s.SourceTree)); } proj.WriteToFile(projPath); string plistPath = Path.Combine(playerPath, "Info.plist"); PlistDocument plist = new PlistDocument(); plist.ReadFromFile(plistPath); PlistElementDict root = plist.root; for (int i = 0; i < m_InfoPlistEntries.Length; i++) { InfoPlistEntry entry = m_InfoPlistEntries[i]; switch (entry.Type) { case PlistEntryType.Boolean: root.SetBoolean(entry.Key, entry.BooleanValue); break; case PlistEntryType.Integer: root.SetInteger(entry.Key, entry.IntegerValue); break; case PlistEntryType.String: root.SetString(entry.Key, entry.StringValue); break; } } plist.WriteToFile(plistPath); var capabilityManager = new ProjectCapabilityManager(projPath, "Unity-iPhone/app.entitlements", "Unity-iPhone"); if (m_EnableGameCenter) { capabilityManager.AddGameCenter(); } if (m_EnableInAppPurchase) { capabilityManager.AddInAppPurchase(); } if (m_EnableKeychainSharing) { capabilityManager.AddKeychainSharing(m_KeychainAccessGroups); } if (m_EnablePushNotifications) { capabilityManager.AddPushNotifications(m_PushNotificationsDevelopment); } capabilityManager.WriteToFile(); #endif }
static void ProcessPBXProject(string pathToBuiltProject) { var unityProjPath = Application.dataPath.Replace("Assets", ""); string projPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj"; PBXProject proj = new PBXProject(); proj.ReadFromString(File.ReadAllText(projPath)); string target = proj.TargetGuidByName("Unity-iPhone"); var settings = GetiOSBuildOptions(); //1.1 framework && lib if (settings.SystemFiles != null) { foreach (var fileName in settings.SystemFiles) { if (fileName.EndsWith(".framework")) { proj.AddFrameworkToProject(target, fileName, false); } else { var fileGuid = proj.AddFile("usr/lib/" + fileName, "Frameworks/" + fileName, PBXSourceTree.Sdk); proj.AddFileToBuild(target, fileGuid); } } } //2 Capabilities if (settings.Capability != null) { foreach (var name in settings.Capability) { switch (name) { case "GameCenter": proj.AddCapability(target, PBXCapabilityType.GameCenter); break; case "InAppPurchase": proj.AddCapability(target, PBXCapabilityType.InAppPurchase); break; case "PushNotifications": proj.AddCapability(target, PBXCapabilityType.PushNotifications); var bundleIdLastIndex = settings.BundleIdentifier.LastIndexOf('.') + 1; var entitlementName = string.Format("{0}.entitlements", settings.BundleIdentifier.Substring(bundleIdLastIndex)); var capManager = new ProjectCapabilityManager(projPath, entitlementName, PBXProject.GetUnityTargetName()); capManager.AddPushNotifications(true); capManager.WriteToFile(); File.Copy(Path.Combine(pathToBuiltProject, entitlementName), Path.Combine(pathToBuiltProject, "Unity-iPhone", entitlementName), true); break; default: break; } } } //3 Info(Info.plist) string plistPath = pathToBuiltProject + "/Info.plist"; var plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); var plistRoot = plist.root; //麦克风权限 plistRoot.SetString("NSMicrophoneUsageDescription", "用于游戏内语音功能时访问麦克风收录语音"); plist.WriteToFile(plistPath); //4 Build Settings // 关闭bitcode(tolua不支持) proj.SetBuildProperty(target, "ENABLE_BITCODE", "NO"); //5 class string unityAppControllerPath = pathToBuiltProject + "/Classes/UnityAppController.mm"; // 6 appiconset if (!string.IsNullOrEmpty(settings.AppIconSetPath)) { string dstPath = pathToBuiltProject + "/Unity-iPhone/Images.xcassets/AppIcon.appiconset/"; string srcPath = Path.Combine(unityProjPath, settings.AppIconSetPath); foreach (var file in Directory.GetFiles(srcPath)) { var to = Path.Combine(dstPath, Path.GetFileName(file)); File.Copy(file, to, true); } } // Save PBXProject proj.WriteToFile(projPath); }
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 AddCapability(MOBXCodeEditorModel xcodeModel, PBXProject xcodeProj, string xcodeTargetGuid, string xcodeTargetPath) { string projectPath = PBXProject.GetPBXProjectPath(xcodeTargetPath); if (xcodeModel.isOpenRestoreScene || xcodeModel.isHaveApple || xcodeModel.associatedDomains.Count > 0) { 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"; } #if UNITY_2018_1_OR_NEWER #if UNITY_2019_3_OR_NEWER ProjectCapabilityManager capManager = new ProjectCapabilityManager(projectPath, entitlementsPath, null, xcodeTargetGuid); #else ProjectCapabilityManager capManager = new ProjectCapabilityManager(projectPath, entitlementsPath, "Unity-iPhone"); #endif if (xcodeModel.associatedDomains.Count > 0 || xcodeModel.isHaveApple) { string[] domains = new string[xcodeModel.associatedDomains.Count]; int index = 0; foreach (string domainStr in xcodeModel.associatedDomains) { Debug.Log("AddCapabilityAssociatedDomains:" + domainStr); domains[index] = domainStr; index++; } //Debug.Log("xcodeTargetGuid:" + xcodeTargetGuid); //Debug.Log("xcodeTargetPath:" + xcodeTargetPath); //Debug.Log("projectPath:" + projectPath); //Debug.Log("GetUnityTargetName:" + PBXProject.GetUnityTargetName()); //Debug.Log("domainStr:" + MiniJSON.jsonEncode(domains)); if (capManager.GetType().GetMethod("AddAssociatedDomains") != null) { capManager.GetType().GetMethod("AddAssociatedDomains").Invoke(capManager, new object[] { domains }); } //Debug.Log("bundleIdentifier:" + UnityEditor.PlayerSettings.applicationIdentifier); //Debug.Log("productName:" + UnityEditor.PlayerSettings.productName); if (xcodeModel.isHaveApple && capManager.GetType().GetMethod("AddSignInWithApple") != null) { capManager.GetType().GetMethod("AddSignInWithApple").Invoke(capManager, null); } //推送 //capManager.AddPushNotifications(true); //内购 //capManager.AddInAppPurchase(); capManager.WriteToFile(); xcodeProj.AddCapability(xcodeTargetGuid, PBXCapabilityType.AssociatedDomains, xcodeTargetPath + "/" + entitlementsPath, true); } #else var entitlementFile = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE plist PUBLIC \" -//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"><plist version = \"1.0\"><dict>"; if (xcodeModel.associatedDomains.Count > 0 || xcodeModel.isHaveApple) { string[] domains = new string[xcodeModel.associatedDomains.Count]; int index = 0; foreach (string domainStr in xcodeModel.associatedDomains) { Debug.Log("AddCapabilityAssociatedDomains:" + domainStr); domains[index] = "<string>" + domainStr + "</string>"; index++; } var associatedDomainsString = ""; if (domains.Length > 0) { associatedDomainsString = "<key>com.apple.developer.associated-domains</key><array>" + string.Join("", domains) + "</array>"; } var appleString = ""; if (xcodeModel.isHaveApple) { appleString = "<key>com.apple.developer.applesignin</key><array><string> Default </string></array>"; } entitlementFile = entitlementFile + associatedDomainsString + appleString + "</dict></plist>"; } Debug.LogWarning(entitlementFile); Debug.LogWarning(xcodeTargetPath + "/" + entitlementsPath); Debug.LogWarning(xcodeTargetPath); StreamWriter sWriter = new StreamWriter(xcodeTargetPath + "/" + entitlementsPath); sWriter.WriteLine(entitlementFile); sWriter.Close(); sWriter.Dispose(); xcodeProj.AddBuildProperty(xcodeTargetGuid, "CODE_SIGN_ENTITLEMENTS", entitlementsPath); string fileGuid = (string)xcodeProj.AddFile(xcodeTargetPath + "/" + entitlementsPath, entitlementsPath, PBXSourceTree.Absolute); xcodeProj.AddFileToBuild(xcodeTargetGuid, fileGuid); #endif } }
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 }
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(); } }