public static void ChangeXcodePlist(BuildTarget buildTarget, string pathToBuiltProject) { #if UNITY_IOS if (buildTarget == BuildTarget.iOS) { // Get plist string plistPath = pathToBuiltProject + "/Info.plist"; PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); // Get root PlistElementDict rootDict = plist.root; // Change value of CFBundleVersion in Xcode plist //var buildKey = "LSApplicationQueriesSchemes"; //rootDict.SetString(buildKey,"<array>\n\t\t<string>aryzon</string>\n\t</array>"); bool changeMade = false; PlistElementArray querieSchemeArray; PlistElement querieSchemeElement; try { rootDict.values.TryGetValue("LSApplicationQueriesSchemes", out querieSchemeElement); querieSchemeArray = querieSchemeElement.AsArray(); } catch { Debug.Log("Could not get value"); querieSchemeArray = rootDict.CreateArray("LSApplicationQueriesSchemes"); changeMade = true; } if (querieSchemeArray != null) { bool foundEntry = false; foreach (PlistElementString obj in querieSchemeArray.values) { if (obj.AsString() == "aryzon") { foundEntry = true; break; } } if (!foundEntry) { querieSchemeArray.AddString("aryzon"); changeMade = true; } } if (changeMade) { // Write to file File.WriteAllText(plistPath, plist.WriteToString()); } } #endif }
/// <summary> /// URLSchemes /// </summary> public static void SetURLSchemes(string buildPath, string urlIdentifier, List <string> schemeList) { PlistDocument plist = GetInfoPlist(buildPath); PlistElementArray urlTypes; if (plist.root.values.ContainsKey(XcodeProjectConst.URL_TYPES_KEY)) { urlTypes = plist.root[XcodeProjectConst.URL_TYPES_KEY].AsArray(); } else { urlTypes = plist.root.CreateArray(XcodeProjectConst.URL_TYPES_KEY); } PlistElementDict itmeDict = urlTypes.AddDict(); itmeDict.SetString(XcodeProjectConst.URL_TYPE_ROLE_KEY, "Editor"); itmeDict.SetString(XcodeProjectConst.URL_IDENTIFIER_KEY, urlIdentifier); PlistElementArray schemesArray = itmeDict.CreateArray(XcodeProjectConst.URL_SCHEMES_KEY); if (itmeDict.values.ContainsKey(XcodeProjectConst.URL_SCHEMES_KEY)) { schemesArray = itmeDict[XcodeProjectConst.URL_SCHEMES_KEY].AsArray(); } else { schemesArray = itmeDict.CreateArray(XcodeProjectConst.URL_SCHEMES_KEY); } for (int i = 0; i < schemesArray.values.Count; i++) { schemeList.Remove(schemesArray.values[i].AsString()); } foreach (string scheme in schemeList) { schemesArray.AddString(scheme); } plist.WriteToFile(GetInfoPlistPath(buildPath)); }
//在info.plist中添加 白名单 private static void AddLSApplicationQueriesSchemes(MOBXCodeEditorModel xcodeModel, PlistElementDict plistElements) { ArrayList LSApplicationQueriesSchemes = xcodeModel.LSApplicationQueriesSchemes; PlistElementArray elementArray = plistElements.CreateArray("LSApplicationQueriesSchemes"); foreach (string str in LSApplicationQueriesSchemes) { elementArray.AddString(str); } }
private static void OnPostprocessBuildIOS(string pathToBuiltProject) { // We use UnityEditor.iOS.Xcode API which only exists in iOS editor module #if UNITY_IOS string projPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj"; UnityEditor.iOS.Xcode.PBXProject proj = new UnityEditor.iOS.Xcode.PBXProject(); proj.ReadFromString(File.ReadAllText(projPath)); proj.AddFrameworkToProject(proj.TargetGuidByName("Unity-iPhone"), "ARKit.framework", false); string target = proj.TargetGuidByName("Unity-iPhone"); Directory.CreateDirectory(Path.Combine(pathToBuiltProject, "Libraries/Unity")); // Check UnityARKitPluginSettings UnityARKitPluginSettings ps = LoadSettings(); string plistPath = Path.Combine(pathToBuiltProject, "Info.plist"); PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); PlistElementDict rootDict = plist.root; // Get or create array to manage device capabilities const string capsKey = "UIRequiredDeviceCapabilities"; PlistElementArray capsArray; PlistElement pel; if (rootDict.values.TryGetValue(capsKey, out pel)) { capsArray = pel.AsArray(); } else { capsArray = rootDict.CreateArray(capsKey); } // Remove any existing "arkit" plist entries const string arkitStr = "arkit"; capsArray.values.RemoveAll(x => arkitStr.Equals(x.AsString())); if (ps.AppRequiresARKit) { // Add "arkit" plist entry capsArray.AddString(arkitStr); } File.WriteAllText(plistPath, plist.WriteToString()); // Add or replace define for facetracking UpdateDefinesInFile(pathToBuiltProject + "/Classes/Preprocessor.h", new Dictionary <string, bool>() { { "ARKIT_USES_FACETRACKING", ps.m_ARKitUsesFacetracking } }); string[] filesToCopy = new string[] { }; for (int i = 0; i < filesToCopy.Length; ++i) { var srcPath = Path.Combine("../PluginSource/source", filesToCopy[i]); var dstLocalPath = "Libraries/" + filesToCopy[i]; var dstPath = Path.Combine(pathToBuiltProject, dstLocalPath); File.Copy(srcPath, dstPath, true); proj.AddFileToBuild(target, proj.AddFile(dstLocalPath, dstLocalPath)); } File.WriteAllText(projPath, proj.WriteToString()); #endif // #if UNITY_IOS }
/// <summary> /// 添加URLSchemes /// </summary> /// <param name="identifier">Identifier.</param> /// <param name="urlScheme">URL scheme.</param> public void AddUrlScheme(string identifier, string urlScheme) { const string KEY = "CFBundleURLTypes"; const string IDENTIFIER_KEY = "CFBundleURLName"; const string URLSCHEMES_KEY = "CFBundleURLSchemes"; PlistElementDict root = _plist.root; PlistElementArray urlTypeList = root[KEY] as PlistElementArray; if (null == urlTypeList) { urlTypeList = root.CreateArray(KEY); } PlistElementDict urlType = null; foreach (PlistElementDict item in urlTypeList.values) { if (item[IDENTIFIER_KEY].AsString() == identifier) { urlType = item; break; } } if (null == urlType) { urlType = urlTypeList.AddDict(); } urlType.SetString(IDENTIFIER_KEY, identifier); PlistElementArray urlSchemes = urlType[URLSCHEMES_KEY] as PlistElementArray; if (null == urlSchemes) { urlSchemes = urlType.CreateArray(URLSCHEMES_KEY); } bool isInclude = false; foreach (PlistElement item in urlSchemes.values) { if (item.AsString() == urlScheme) { isInclude = true; break; } } if (false == isInclude) { urlSchemes.AddString(urlScheme); } }
static void ModifyPlist(string path) { // Info.plist string plistPath = path + "/Info.plist"; PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(path: plistPath)); // ROOT PlistElementDict rootDict = plist.root; PlistElementArray urlTypes = rootDict.CreateArray("CFBundleURLTypes"); // Add URLScheme For Wechat PlistElementDict wxUrl = urlTypes.AddDict(); wxUrl.SetString("CFBundleTypeRole", "Editor"); wxUrl.SetString("CFBundleURLName", "weixin"); wxUrl.SetString("CFBundleURLSchemes", val: Config.wechatAppId); PlistElementArray wxUrlScheme = wxUrl.CreateArray("CFBundleURLSchemes"); wxUrlScheme.AddString(val: Config.wechatAppId); // Add URLScheme For jiguang PlistElementDict jgUrl = urlTypes.AddDict(); jgUrl.SetString("CFBundleTypeRole", "Editor"); jgUrl.SetString("CFBundleURLName", "jiguang"); jgUrl.SetString("CFBundleURLSchemes", val: "jiguang-" + Config.jgAppKey); PlistElementArray jgUrlScheme = jgUrl.CreateArray("CFBundleURLSchemes"); jgUrlScheme.AddString(val: "jiguang-" + Config.jgAppKey); // 白名单 for wechat PlistElementArray queriesSchemes = rootDict.CreateArray("LSApplicationQueriesSchemes"); queriesSchemes.AddString("wechat"); queriesSchemes.AddString("weixin"); queriesSchemes.AddString(val: Config.wechatAppId); // HTTP 设置 const string atsKey = "NSAppTransportSecurity"; PlistElementDict dictTmp = rootDict.CreateDict(key: atsKey); dictTmp.SetBoolean("NSAllowsArbitraryLoads", true); PlistElementArray backModes = rootDict.CreateArray("UIBackgroundModes"); backModes.AddString("remote-notification"); // 出口合规信息 rootDict.SetBoolean("ITSAppUsesNonExemptEncryption", false); // 写入 File.WriteAllText(path: plistPath, plist.WriteToString()); }
private void ChangeEntitlementAssociatedDomains(string entitlementFilePath, AppLinkingConfiguration configuration) { PlistDocument entitlementFile = new PlistDocument(); entitlementFile.ReadFromString(File.ReadAllText(entitlementFilePath)); PlistElementDict rootElement = entitlementFile.root; var mtarget = _target == BuildTarget.iOS ? SupportedPlatforms.iOS : SupportedPlatforms.tvOS; var configs = configuration.GetPlatformDomainProtocols(mtarget, true).Select(d => d.Host) .Distinct().ToArray(); if (configs.Length != 0) { var associatedDomainsArrayElement = rootElement[AssociatedDomainsKey] as PlistElementArray; var alreadySetupDomains = new string[0]; if (associatedDomainsArrayElement == null) { associatedDomainsArrayElement = rootElement.CreateArray(AssociatedDomainsKey); } else { try { alreadySetupDomains = associatedDomainsArrayElement.values.Select(a => a.AsString()).ToArray(); } catch (Exception e) { } } // // The except removes any config when the Append is used in the generation // foreach (var domainProtocol in configs.Where(c => alreadySetupDomains.Any(d => d.Contains(c)) == false)) { associatedDomainsArrayElement.AddString(AppLinksKey + domainProtocol); } } else { if (rootElement.values.ContainsKey(AssociatedDomainsKey)) { rootElement.values.Remove(AssociatedDomainsKey); } } File.WriteAllText(entitlementFilePath, entitlementFile.WriteToString()); }
public static void UpdateXCodePlist(BuildTarget buildTarget, string pathToBuiltProject) { #if UNITY_IOS if (buildTarget == BuildTarget.iOS) { // Check Consumer Key if (string.IsNullOrEmpty(TwitterSettings.ConsumerKey)) { TwitterKit.Internal.Utils.LogError(TwitterSettings.API_KEY_NOT_SET); return; } // Get plist string plistPath = pathToBuiltProject + "/Info.plist"; PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); // Get root PlistElementDict rootDict = plist.root; // Modify Info.Plist for Twitter Kit (https://dev.twitter.com/twitterkit/ios/installation) PlistElementArray bundleURLTypesArray = rootDict[URL_TYPES] as PlistElementArray; if (bundleURLTypesArray == null) { bundleURLTypesArray = rootDict.CreateArray(URL_TYPES); } PlistElementDict dict = bundleURLTypesArray.AddDict(); PlistElementArray bundleURLSchemesArray = dict.CreateArray(URL_SCHEMES); bundleURLSchemesArray.AddString("twitterkit-" + TwitterSettings.ConsumerKey); PlistElementArray queriesSchemesArray = rootDict[APPLICATION_QUERIES_SCHEMES] as PlistElementArray; if (queriesSchemesArray == null) { queriesSchemesArray = rootDict.CreateArray(APPLICATION_QUERIES_SCHEMES); } queriesSchemesArray.AddString("twitter"); queriesSchemesArray.AddString("twitterauth"); // Write to file File.WriteAllText(plistPath, plist.WriteToString()); } #endif }
public static void OnPostProcessBuild(BuildTarget target, string targetPath) { settings = BuildPipelineIOSSettings.Instance; if (target == BuildTarget.iOS) { try { string plistPath = targetPath + "/Info.plist"; PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); // Get root PlistElementDict rootDict = plist.root; // background location useage key (new in iOS 8) rootDict.SetString("NSLocationAlwaysUsageDescription", "Uses background location"); // background modes PlistElementArray bgModes = rootDict.CreateArray("UIBackgroundModes"); bgModes.AddString("location"); bgModes.AddString("fetch"); if (settings.setURLSchemes) { if (settings.urlSchemes != null && settings.urlSchemes.Length > 0) { PlistElementArray urlSchemes = rootDict.CreateArray("CFBundleURLSchemes"); for (int i = 0; i < settings.urlSchemes.Length; i++) { urlSchemes.AddString(settings.urlSchemes[i]); } } else { Debug.LogWarning("Cannot set URL Schemes because it's null or empty."); } } // Write to file File.WriteAllText(plistPath, plist.WriteToString()); } catch (Exception e) { Debug.LogException(e); } } }
static void AddEntitlements(string pathToBuiltProject) { string entitlementsPath = Path.Combine(pathToBuiltProject, string.Format("./Unity-iPhone/{0}", ENTITLEMENTS_NAME)); PlistDocument plist = new PlistDocument(); PlistElementDict rootDict = plist.root; PlistElementArray deviceCapabilityArray = rootDict.CreateArray("com.apple.developer.icloud-container-identifiers"); deviceCapabilityArray.AddString("iCloud.$(CFBundleIdentifier)"); PlistElementArray serviceArray = rootDict.CreateArray("com.apple.developer.icloud-services"); serviceArray.AddString("CloudDocuments"); PlistElementArray ubiquityArray = rootDict.CreateArray("com.apple.developer.ubiquity-container-identifiers"); ubiquityArray.AddString("iCloud.$(CFBundleIdentifier)"); rootDict.SetString("com.apple.developer.ubiquity-kvstore-identifier", "$(TeamIdentifierPrefix)$(CFBundleIdentifier)"); using (StreamWriter sw = File.CreateText(entitlementsPath)) { sw.WriteLine(plist.WriteToString()); } }
private static void SetBackgroundModes(PlistDocument plist, List <string> modes) { PlistElementDict rootDict = plist.root; PlistElementArray bgModes = rootDict.CreateArray("UIBackgroundModes"); int count = modes.Count; for (int i = 0; i < count; i++) { bgModes.AddString(modes[i]); } }
private static void UpdateProjectPlist(string plistPath) { PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); PlistElementDict rootDict = plist.root; rootDict.CreateArray("UIBackgroundModes").AddString("remote-notification"); File.WriteAllText(plistPath, plist.WriteToString()); }
private static PlistDocument AddNFCEntitlement(ProjectCapabilityManager projectCapabilityManager) { MethodInfo getMethod = projectCapabilityManager.GetType().GetMethod("GetOrCreateEntitlementDoc", BindingFlags.NonPublic | BindingFlags.Instance); PlistDocument entitlementDoc = (PlistDocument)getMethod.Invoke(projectCapabilityManager, new object[] { }); PlistElementDict dictionary = entitlementDoc.root; PlistElementArray array = dictionary.CreateArray("com.apple.developer.nfc.readersession.formats"); array.values.Add(new PlistElementString("NDEF")); return(entitlementDoc); }
private static PlistElementArray GetCustomTypesArray(PlistElementDict rootDict, bool isExported) { string key = isExported ? "UTExportedTypeDeclarations" : "UTImportedTypeDeclarations"; PlistElementArray result = rootDict[key] as PlistElementArray; if (result == null) { result = rootDict.CreateArray(key); } return(result); }
public static void OnPostprocessBuild(BuildTarget BuildTarget, string path) { if (BuildTarget == BuildTarget.iOS) { string projPath = PBXProject.GetPBXProjectPath(path); PBXProject proj = new PBXProject(); proj.ReadFromString(File.ReadAllText(projPath)); // 获取当前项目名字 string target = proj.TargetGuidByName(PBXProject.GetUnityTargetName()); // 对所有的编译配置设置选项 proj.SetBuildProperty(target, "ENABLE_BITCODE", "NO"); // 添加依赖库 // 语音sdk proj.AddFrameworkToProject(target, "Security.framework", false); proj.AddFrameworkToProject(target, "CoreTelephony.framework", false); proj.AddFrameworkToProject(target, "libc++.tbd", false); proj.AddFrameworkToProject(target, "libz.tbd", false); proj.AddFrameworkToProject(target, "libsqlite3.0.tbd", false); //proj.AddFrameworkToProject(target, "Frameworks/Plugins/iOS/AlipaySDK/AlipaySDK.framework", false); #if UKGAME_SDK proj.AddFrameworkToProject(target, "Frameworks/Plugins/iOS/UKGame_SDK/YKSDK.framework", false); #endif // 设置签名 // proj.SetBuildProperty (target, "CODE_SIGN_IDENTITY", "iPhone Distribution: _______________"); // proj.SetBuildProperty (target, "PROVISIONING_PROFILE", "********-****-****-****-************"); // 保存工程 proj.WriteToFile(projPath); // 修改plist string plistPath = path + "/Info.plist"; PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); PlistElementDict rootDict = plist.root; //设置微信支付宝白名单 PlistElementArray array = rootDict.CreateArray("LSApplicationQueriesSchemes"); array.AddString("weixin"); array.AddString("wechat"); //array.AddString("alipay"); // 语音所需要的声明,iOS10必须 rootDict.SetString("NSContactsUsageDescription", "是否允许此游戏使用麦克风?"); // 保存plist plist.WriteToFile(plistPath); } }
public static void OnPostProcessBuild(BuildTarget buildTarget, string buildPath) { if (buildTarget == BuildTarget.iOS) { // var projPath = PBXProject.GetPBXProjectPath(buildPath); var projPath = buildPath + "/Unity-iPhone.xcodeproj/project.pbxproj"; var proj = new PBXProject(); proj.ReadFromFile(projPath); string targetGuid = proj.TargetGuidByName(PBXProject.GetUnityTargetName()); //// Configure build settings proj.SetBuildProperty(targetGuid, "ENABLE_BITCODE", "NO"); proj.SetBuildProperty(targetGuid, "SWIFT_OBJC_BRIDGING_HEADER", "Libraries/LoomSDK/ios/LoomSDKSwift-Bridging-Header.h"); proj.SetBuildProperty(targetGuid, "SWIFT_OBJC_INTERFACE_HEADER_NAME", "LoomSDKSwift.h"); proj.AddBuildProperty(targetGuid, "LD_RUNPATH_SEARCH_PATHS", "@executable_path/Frameworks"); proj.AddBuildProperty(targetGuid, "LD_RUNPATH_SEARCH_PATHS", "@executable_path/Libraries/LoomSDK/Frameworks"); proj.SetBuildProperty(targetGuid, "SWIFT_VERSION", "3.0"); //frameworks DirectoryInfo projectParent = Directory.GetParent(Application.dataPath); char divider = Path.DirectorySeparatorChar; DirectoryInfo destinationFolder = new DirectoryInfo(buildPath + divider + "Frameworks/LoomSDK/Frameworks"); foreach (DirectoryInfo file in destinationFolder.GetDirectories()) { string filePath = "Frameworks/LoomSDK/Frameworks/" + file.Name; //proj.AddFile(filePath, filePath, PBXSourceTree.Source); string fileGuid = proj.AddFile(filePath, filePath, PBXSourceTree.Source); proj.AddFrameworkToProject(targetGuid, file.Name, false); PBXProjectExtensions.AddFileToEmbedFrameworks(proj, targetGuid, fileGuid); } proj.WriteToFile(projPath); //info.plist var plistPath = buildPath + "/Info.plist"; var plist = new PlistDocument(); plist.ReadFromFile(plistPath); // Update value PlistElementDict rootDict = plist.root; //rootDict.SetString("CFBundleIdentifier","$(PRODUCT_BUNDLE_IDENTIFIER)"); PlistElementArray urls = rootDict.CreateArray("CFBundleURLTypes"); PlistElementDict dic = urls.AddDict(); PlistElementArray scheme = dic.CreateArray("CFBundleURLSchemes"); scheme.AddString(PlayerSettings.applicationIdentifier); dic.SetString("CFBundleURLName", "auth0"); // Write plist File.WriteAllText(plistPath, plist.WriteToString()); } }
[PostProcessBuild(10)] // We should try to run last public static void OnPostprocessBuild(BuildTarget buildTarget, string buildPath) { #if UNITY_IPHONE if (buildTarget != BuildTarget.iOS) { return; } string _projectPath = buildPath + "/Unity-iPhone.xcodeproj/project.pbxproj"; PBXProject _project = new PBXProject(); _project.ReadFromFile(_projectPath); string _target = _project.TargetGuidByName("Unity-iPhone"); _project.SetBuildProperty(_target, "ENABLE_BITCODE", "NO"); _project.SetBuildProperty(_target, "CLANG_ENABLE_MODULES", "YES"); _project.AddCapability(_target, PBXCapabilityType.InAppPurchase); _project.AddCapability(_target, PBXCapabilityType.PushNotifications); _project.WriteToFile(_projectPath); UnityEngine.Debug.Log("iOSPostProcessor: Disable BITCODE"); UnityEngine.Debug.Log("iOSPostProcessor: Enable CLANG MODULES"); // Get plist string plistPath = buildPath + "/Info.plist"; PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); // Get root PlistElementDict rootDict = plist.root; // Change value of CFBundleVersion in Xcode plist var buildKey = "UIBackgroundModes"; rootDict.CreateArray(buildKey).AddString("remote-notification"); UnityEngine.Debug.Log("iOSPostProcessor: Enable background modes: remote-notification"); rootDict.SetBoolean("ITSAppUsesNonExemptEncryption", false); UnityEngine.Debug.Log("iOSPostProcessor: Set Export compliance status"); rootDict.SetString("NSCalendarsUsageDescription", "App using calendar"); UnityEngine.Debug.Log("iOSPostProcessor: Set NSCalendarsUsageDescription"); // Write to file File.WriteAllText(plistPath, plist.WriteToString()); #endif }
public static void ChangeXcodePlist(BuildTarget buildTarget, string pathToBuiltProject) { if (buildTarget == BuildTarget.iOS) { // Get plist string plistPath = pathToBuiltProject + "/Info.plist"; PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); // Get root PlistElementDict rootDict = plist.root; // PlistElementArray queriesSchemes = rootDict.CreateArray("LSApplicationQueriesSchemes"); queriesSchemes.AddString("fb"); queriesSchemes.AddString("instagram"); queriesSchemes.AddString("tumblr"); queriesSchemes.AddString("twitter"); rootDict.CreateDict("NSCalendarsUsageDescription"); rootDict.SetString("NSCalendarsUsageDescription", "Adding events"); rootDict.CreateDict("NSPhotoLibraryUsageDescription"); rootDict.SetString("NSPhotoLibraryUsageDescription", "Taking selfies"); rootDict.CreateDict("NSCameraUsageDescription"); rootDict.SetString("NSCameraUsageDescription", "Taking selfies"); rootDict.CreateDict("NSMotionUsageDescription"); rootDict.SetString("NSMotionUsageDescription", "Interactive ad controls"); rootDict.CreateDict("NSBluetoothPeripheralUsageDescription"); rootDict.SetString("NSBluetoothPeripheralUsageDescription", "Advertisement would like to use bluetooth."); PlistElementArray bundleURLTypes = rootDict.CreateArray("CFBundleURLTypes"); PlistElementDict bundleURLTypesDic = bundleURLTypes.AddDict(); PlistElementArray bundleURLSchemes = bundleURLTypesDic.CreateArray("CFBundleURLSchemes"); bundleURLSchemes.AddString("fbYOUR-FB-ID"); rootDict.CreateDict("FacebookAppID"); rootDict.SetString("FacebookAppID", "YOUR-FB-ID"); rootDict.CreateDict("FacebookDisplayName"); rootDict.SetString("FacebookDisplayName", "Nuumbers"); rootDict.CreateDict("AppLovinSdkKey"); rootDict.SetString("AppLovinSdkKey", "YOUR-SDK-KEY"); // Write to file File.WriteAllText(plistPath, plist.WriteToString()); } }
static PlistElementArray GetOrCreateArray(PlistElementDict dict, string key) { PlistElement array = dict[key]; if (array != null) { return(array.AsArray()); } else { return(dict.CreateArray(key)); } }
/// <summary> /// 设置URL Schemes /// </summary> public void SetURLSchemes(string role, string bundleURLName, List <string> schemes) { PlistElementArray urlTypes; if (root.values.ContainsKey(BUNDLE_URL_TYPES_KEY)) { urlTypes = root[BUNDLE_URL_TYPES_KEY].AsArray(); } else { urlTypes = root.CreateArray(BUNDLE_URL_TYPES_KEY); } PlistElementDict itmeDict = urlTypes.AddDict(); itmeDict.SetString(BUNDLE_URL_TYPE_ROLE_KEY, role); itmeDict.SetString(BUNDLE_URL_IDENTIFIER_KEY, bundleURLName); PlistElementArray schemesArray = itmeDict.CreateArray(BUNDLE_URL_SCHEMES_KEY); if (itmeDict.values.ContainsKey(BUNDLE_URL_SCHEMES_KEY)) { schemesArray = itmeDict[BUNDLE_URL_SCHEMES_KEY].AsArray(); } else { schemesArray = itmeDict.CreateArray(BUNDLE_URL_SCHEMES_KEY); } for (int i = 0; i < schemesArray.values.Count; i++) { schemes.Remove(schemesArray.values[i].AsString()); } foreach (string scheme in schemes) { schemesArray.AddString(scheme); } }
/// <summary> /// 設定GameKit到Plist上 /// </summary> protected void AddGameKitToPlist() { Debug.Log("Start AddGameKitToPlist"); PlistDocument aPDoc = GetProjectPlist(); PlistElementDict aRootDict = aPDoc.root; PlistElementArray aDeviceCapArray = aRootDict.CreateArray("UIRequiredDeviceCapabilities"); aDeviceCapArray.AddString("armv7"); aDeviceCapArray.AddString("gamekit"); File.WriteAllText(mInfoPlistFullPath, aPDoc.WriteToString()); }
static void ChangePlist(string pathToBuildProject) { string path = string.Format("{0}/Info.plist", pathToBuildProject); PlistDocument doc = new PlistDocument(); doc.ReadFromString(File.ReadAllText(path)); PlistElementDict root = doc.root; // 对iOS9的影响 { PlistElementDict security = root.CreateDict("NSAppTransportSecurity"); security.SetBoolean("NSAllowsArbitraryLoads", true); } // 合规证明 { root.SetBoolean("ITSAppUsesNonExemptEncryption", false); } // 添加Scheme白名单 { PlistElementArray schemes = root.CreateArray("LSApplicationQueriesSchemes"); schemes.AddString("fbapi"); schemes.AddString("fbauth2"); schemes.AddString("fb-messenger-api"); } // fb { string idFacebook = "212915212149962"; root.SetString("FacebookAppID", idFacebook); root.SetString("FacebookDisplayName", PlayerSettings.productName); PlistElementArray types = root.CreateArray("CFBundleURLTypes"); PlistElementDict dict = types.AddDict(); dict.SetString("CFBundleTypeRole", "Editor"); PlistElementArray schemes = dict.CreateArray("CFBundleURLSchemes"); schemes.AddString("fb" + idFacebook); } // 权限 { root.SetString("NSPhotoLibraryUsageDescription", "使用相册"); root.SetString("NSCameraUsageDescription", "使用相机"); } File.WriteAllText(path, doc.WriteToString()); }
private static void AddCapabilitiesFieldToInfoPlist(string pathToBuildProject, string key, string value, PlistElement type) { string plistFilePath = Path.Combine(pathToBuildProject, "Info.plist"); if (File.Exists(plistFilePath) == false) { return; } if (key.Length < 1 || value.Length < 1) { return; } PlistDocument plist = new PlistDocument(); plist.ReadFromFile(plistFilePath); PlistElementDict rootDic = plist.root; if (rootDic.values.ContainsKey(key) == false) { if (type is PlistElementString) { rootDic.SetString(key, value); } else if (type is PlistElementArray) { rootDic.CreateArray(key).AddString(value); } } else { if (type is PlistElementString) { rootDic.SetString(key, value); } else if (type is PlistElementArray) { PlistElementArray array = rootDic.values[key].AsArray(); foreach (PlistElement item in array.values) { if (item.AsString() == value) { Debug.LogWarningFormat("alread exist {0}:{1} in Info.plist", key, value); return; } } array.AddString(value); } } File.WriteAllText(plistFilePath, plist.WriteToString()); }
protected virtual void ChangePList(string _path) { PlistDocument _plist = new PlistDocument(); _plist.ReadFromString(File.ReadAllText(_path)); PlistElementDict _rootDict = _plist.root; PlistElementArray _tempList = new PlistElementArray(); PlistElementDict _tempDict = new PlistElementDict(); //设置 CFBundleURLTypes PlistElementArray _plistArray = _rootDict.CreateArray("CFBundleURLTypes"); if (_plistArray == null) { _plistArray = new PlistElementArray(); } //微信 _tempDict = _plistArray.AddDict(); _tempDict.SetString("CFBundleTypeRole", "Editor"); _tempDict.SetString("CFBundleURLName", "weixin"); _tempList = _tempDict.CreateArray("CFBundleURLSchemes"); _tempList.AddString(ChannelData.current.wxappID); //白名单 _plistArray = _rootDict.CreateArray("LSApplicationQueriesSchemes"); if (_plistArray == null) { _plistArray = new PlistElementArray(); } //微信 _plistArray.AddString("weixin"); //rootDict.SetString("CFBundleVersion", "11"); File.WriteAllText(_path, _plist.WriteToString()); }
static void AddDeviceCapabilities(string pathToBuiltProject) { string infoPlistPath = Path.Combine(pathToBuiltProject, "./Info.plist"); PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(infoPlistPath)); PlistElementDict rootDict = plist.root; PlistElementArray deviceCapabilityArray = rootDict.CreateArray("UIRequiredDeviceCapabilities"); deviceCapabilityArray.AddString("armv7"); deviceCapabilityArray.AddString("gamekit"); File.WriteAllText(infoPlistPath, plist.WriteToString()); }
public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject) { Debug.Log("[OnPostprocessBuild] target = " + target + ", pathToBuiltProject = " + pathToBuiltProject); if (target == BuildTarget.iOS) { string plistPath = pathToBuiltProject + "/Info.plist"; PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); // Get root var typesKey = "CFBundleURLTypes"; PlistElementDict rootDict = plist.root; var types = rootDict[typesKey]; if (types == null) { types = rootDict.CreateArray(typesKey); } var ta = types.AsArray(); var newScheme = ta.AddDict(); newScheme.SetString("CFBundleURLName", "com.solitaire.omg"); var schems = newScheme.CreateArray("CFBundleSchemes"); schems.AddString("omgsolitaire"); // Write to file File.WriteAllText(plistPath, plist.WriteToString()); #if UNITY_EDITOR_OSX string xcodeProjectPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj"; PBXProject xcodeProject = new PBXProject(); xcodeProject.ReadFromFile(xcodeProjectPath); // setting bitcode to No string xcodeTarget = xcodeProject.TargetGuidByName("Unity-iPhone"); xcodeProject.SetBuildProperty(xcodeTarget, "ENABLE_BITCODE", "NO"); xcodeProject.AddBuildProperty(xcodeTarget, "OTHER_LDFLAGS", "-ObjC"); xcodeProject.AddBuildProperty(xcodeTarget, "CLANG_ENABLE_MODULES", "YES"); xcodeProject.AddFrameworkToProject(xcodeTarget, "AdSupport.framework", true); xcodeProject.AddFrameworkToProject(xcodeTarget, "iAd.framework", true); xcodeProject.AddFrameworkToProject(xcodeTarget, "GoogleMobileAds.framework", false); // Save the changes to Xcode project file. xcodeProject.WriteToFile(xcodeProjectPath); #endif } }
static void OnPostprocessBuild(BuildTarget buildTarget, string path) { var plistPath = Path.Combine(path, "Info.plist"); var plist = new PlistDocument(); plist.ReadFromFile(plistPath); PlistElementDict rootDict = plist.root; PlistElementDict dic = rootDict.CreateArray("CFBundleURLTypes").AddDict(); dic.SetString("CFBundleURLName", "com.mark.ThirdApp"); dic.CreateArray("CFBundleURLSchemes").AddString("thirdapp"); File.WriteAllText(plistPath, plist.WriteToString()); }
//在info.plist中添加 URLSchemes private static void AddURLSchemes(MOBXCodeEditorModel xcodeModel,PlistElementDict plistElements) { ArrayList URLSchemes = xcodeModel.URLSchemes; PlistElementArray elementArray = plistElements.CreateArray ("CFBundleURLTypes"); foreach (Hashtable scheme in URLSchemes) { PlistElementDict dict = elementArray.AddDict (); dict.SetString ("CFBundleURLName",(string)scheme["CFBundleURLName"]); PlistElementArray urlArray = dict.CreateArray ("CFBundleURLSchemes"); ArrayList schemes = (ArrayList)scheme ["CFBundleURLSchemes"]; foreach (string schemeStr in schemes) { urlArray.AddString (schemeStr); } } }
public static void SetiOSUrlId(string urlId, PlistElementDict rootDict) { PlistElementArray urlTypesArray = rootDict["CFBundleURLTypes"] != null ? rootDict["CFBundleURLTypes"].AsArray() : rootDict.CreateArray("CFBundleURLTypes"); PlistElementDict urlTypes = urlTypesArray.AddDict(); urlTypes.SetString("CFBundleTypeRole", "Editor"); urlTypes.SetString("CFBundleURLName", urlId); PlistElementArray urlSchemes = urlTypes.CreateArray("CFBundleURLSchemes"); urlSchemes.AddString(urlId); }
public static void ModifyFrameworkAndInfoList(BuildTarget BuildTarget, string path) { if (BuildTarget == BuildTarget.iOS) { string projPath = PBXProject.GetPBXProjectPath(path); PBXProject proj = new PBXProject(); proj.ReadFromString(File.ReadAllText(projPath)); string xtarget = proj.TargetGuidByName("Unity-iPhone"); // add extra framework(s) proj.AddFrameworkToProject(xtarget, "AssetsLibrary.framework", false); // set code sign identity & provisioning profile proj.SetBuildProperty(xtarget, "CODE_SIGN_IDENTITY", "iPhone Distribution: _______________"); proj.SetBuildProperty(xtarget, "PROVISIONING_PROFILE", "********-****-****-****-************"); // rewrite to file File.WriteAllText(projPath, proj.WriteToString()); // 由于我的开发机是英文系统,但游戏需要设置为中文; // 需要在修改 Info.plist 中的 CFBundleDevelopmentRegion 字段为 zh_CN // Get plist string plistPath = path + "/Info.plist"; PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); // Get root PlistElementDict rootDict = plist.root; // Change value of CFBundleDevelopmentRegion in Xcode plist rootDict.SetString("CFBundleDevelopmentRegion", "zh_CN"); PlistElementArray urlTypes = rootDict.CreateArray("CFBundleURLTypes"); // add weixin url scheme PlistElementDict wxUrl = urlTypes.AddDict(); wxUrl.SetString("CFBundleTypeRole", "Editor"); wxUrl.SetString("CFBundleURLName", "weixin"); PlistElementArray wxUrlScheme = wxUrl.CreateArray("CFBundleURLSchemes"); wxUrlScheme.AddString("____________"); // Write to file File.WriteAllText(plistPath, plist.WriteToString()); } }