public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject) { if (target != BuildTarget.iOS) { return; } string path = Path.Combine(pathToBuiltProject, "Info.plist"); var plist = new PlistDocument(); plist.ReadFromFile(path); PlistElementArray schemes = plist.root["LSApplicationQueriesSchemes"] as PlistElementArray; if (schemes == null) { schemes = plist.root.CreateArray("LSApplicationQueriesSchemes"); } string[] scheveValues = schemes.values.Select(e => (e as PlistElementString).value).ToArray(); if (!scheveValues.Contains("line")) { schemes.AddString("line"); } if (!scheveValues.Contains("instagram")) { schemes.AddString("instagram"); } plist.WriteToFile(path); }
public static void ChangeXCodePlist(BuildTarget buildTarget, string pathToBuiltProject) { const string iPadOrientations = "UISupportedInterfaceOrientations~ipad"; Debug.Log("build target: " + buildTarget); Debug.Log("path: " + pathToBuiltProject); if (buildTarget == BuildTarget.iOS) { string plistPath = pathToBuiltProject + "/Info.plist"; PlistDocument plist = new PlistDocument(); plist.ReadFromFile(plistPath); PlistElementDict root = plist.root; if (iosExtraProperties.iPadLandscapeEnable) { Debug.Log("Adding landscape for iPad"); PlistElementArray arr = new PlistElementArray(); arr.AddString("UIInterfaceOrientationPortrait"); arr.AddString("UIInterfaceOrientationPortraitUpsideDown"); arr.AddString("UIInterfaceOrientationLandscapeLeft"); arr.AddString("UIInterfaceOrientationLandscapeRight"); root[iPadOrientations] = arr; } else { Debug.Log("removing iPad entries..."); root[iPadOrientations] = null; } plist.WriteToFile(plistPath); } }
public static void OnPostProcessBuild(BuildTarget buildTarget, string path) { if (buildTarget == BuildTarget.iOS) { // Update configuration string projectPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj"; PBXProject pbxProject = new PBXProject(); pbxProject.ReadFromFile(projectPath); string target = pbxProject.GetUnityMainTargetGuid(); string targetFramework = pbxProject.GetUnityFrameworkTargetGuid(); pbxProject.SetBuildProperty(target, "ENABLE_BITCODE", "NO"); pbxProject.SetBuildProperty(targetFramework, "ENABLE_BITCODE", "NO"); pbxProject.WriteToFile(projectPath); // Update plist string plistPath = path + "/Info.plist"; PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); PlistElementDict rootDict = plist.root; PlistElementArray bgModes = rootDict.CreateArray("UISupportedExternalAccessoryProtocols"); bgModes.AddString("io.structure.depth"); bgModes.AddString("io.structure.infrared"); bgModes.AddString("io.structure.control"); File.WriteAllText(plistPath, plist.WriteToString()); } }
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; // background location useage key (new in iOS 8) rootDict.SetString("NSLocationAlwaysUsageDescription", "The challenge will be update your progress after you turn off the screen."); rootDict.SetString("NSLocationWhenInUseUsageDescription", "Know in which district you are."); //First of all you have to activate the background processing in 'Background Mode'. // background modes // https://developer.apple.com/documentation/bundleresources/information_property_list/uibackgroundmodes PlistElementArray bgModes = rootDict.CreateArray("UIBackgroundModes"); bgModes.AddString("location"); bgModes.AddString("fetch"); bgModes.AddString("audio"); bgModes.AddString("processing"); // Write to file File.WriteAllText(plistPath, plist.WriteToString()); } }
public static void SetupXcodeSettingsForToriki(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; // 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()); } }
private static void OnPostprocessBuild(BuildTarget buildTarget, string buildPath) { if (buildTarget != BuildTarget.iOS) { return; } if (LineLoginSetting.IsValid() == false) { Debug.LogErrorFormat("no LineLoginSetting Asset In Resources or Invalid"); } if (string.IsNullOrEmpty(LineLoginSetting.ChannelID)) { Debug.LogAssertion("channelId is INVALID! please set channelID use [Tools/Line Login]"); } string plistPath = LineLoginSetting.GetInfoPlistPath(buildPath); PlistDocument plist = new PlistDocument(); plist.ReadFromFile(plistPath); string pbxProjPath = PBXProject.GetPBXProjectPath(buildPath); PBXProject pbxProject = new PBXProject(); pbxProject.ReadFromString(File.ReadAllText(pbxProjPath)); string targetGuid = pbxProject.TargetGuidByName(PBXProject.GetUnityTargetName()); pbxProject.UpdateBuildProperty(targetGuid, "OTHER_LDFLAGS", new string[] { "-ObjC" }, null); File.WriteAllText(pbxProjPath, pbxProject.WriteToString()); if (plist.root.values.ContainsKey("LineSDKConfig")) { plist.root.values.Remove("LineSDKConfig"); } if (plist.root.values.ContainsKey("CFBundleURLTypes")) { plist.root.values.Remove("CFBundleURLTypes"); } if (plist.root.values.ContainsKey("LSApplicationQueriesSchemes")) { plist.root.values.Remove("LSApplicationQueriesSchemes"); } plist.root.CreateDict("LineSDKConfig").SetString("ChannelID", LineLoginSetting.ChannelID); PlistElementArray CFBundleURLTypes = plist.root.CreateArray("CFBundleURLTypes"); PlistElementDict CFBundleURLTypesDict = CFBundleURLTypes.AddDict(); CFBundleURLTypesDict.SetString("CFBundleTypeRole", "Editor"); CFBundleURLTypesDict.SetString("CFBundleTypeName", "linelogin"); //$(PRODUCT_BUNDLE_IDENTIFIER) dosen't works for CFBundleTypeSchemes? //CFBundleURLTypesDict.CreateArray("CFBundleURLSchemes").AddString("line3rdp.$(PRODUCT_BUNDLE_IDENTIFIER)"); CFBundleURLTypesDict.CreateArray("CFBundleURLSchemes").AddString("line3rdp." + Application.identifier); PlistElementArray arr = plist.root.CreateArray("LSApplicationQueriesSchemes"); arr.AddString("lineauth"); arr.AddString("line3rdp." + Application.identifier); plist.WriteToFile(LineLoginSetting.GetInfoPlistPath(buildPath)); Debug.Log("iOS Line Login Post Process done. with ChannelID:" + LineLoginSetting.ChannelID); }
private static void OnPostProcessBuild(BuildTarget target, string buildPath) { // App plist string plistPath = buildPath + "/Info.plist"; PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); PlistElementDict rootDict = plist.root; // Background Modes PlistElementArray bgModes = rootDict.CreateArray("UIBackgroundModes"); bgModes.AddString("remote-notification"); bgModes.AddString("fetch"); bgModes.AddString("processing"); // Background Task PlistElementArray bgTasks = rootDict.CreateArray("BGTaskSchedulerPermittedIdentifiers"); bgTasks.AddString("com.openback.bgtask.refresh"); bgTasks.AddString("com.openback.bgtask.check"); // Allowed deep links //PlistElementArray queriesSchemes = rootDict.CreateArray("LSApplicationQueriesSchemes"); //queriesSchemes.AddString("instagram"); // OpenBack Settings OpenBackConfig config = OpenBackConfig.Load(); var openback = rootDict.CreateDict("OpenBack"); if (!String.IsNullOrEmpty(config.IOSAppCode)) { openback.SetString("AppCode", config.IOSAppCode); } if (!String.IsNullOrEmpty(config.IOSAppGroup)) { AddAppGroup(buildPath, config.IOSAppGroup); openback.SetString("AppGroup", config.IOSAppGroup); } openback.SetInteger("DebugLevel", (int)config.IOSLogLevel); openback.SetBoolean("EnableAutoStart", config.IOSEnableAutoStart); openback.SetBoolean("ClearBadgeCount", config.IOSEnableAutoStart); openback.SetBoolean("EnableCoreMotionActivity", config.IOSEnableCoreMotion); openback.SetBoolean("EnableMicrophone", config.IOSEnableMicrophone); openback.SetBoolean("EnableProximity", config.IOSEnableProximity); openback.SetBoolean("EnableSwizzle", config.IOSEnableSwizzle); if (!String.IsNullOrEmpty(config.IOSNotificationLargeIcon)) { openback.SetString("LargeIcon", config.IOSNotificationLargeIcon); } if (!String.IsNullOrEmpty(config.IOSNotificationSound)) { openback.SetString("NotificationSound", config.IOSNotificationSound); } File.WriteAllText(plistPath, plist.WriteToString()); }
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; // Remote notifications (Megacool sdk, etc) var buildKey = "UIBackgroundModes"; rootDict.CreateArray(buildKey).AddString("remote-notification"); // 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 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()); }
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); } }
/// <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()); }
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 AddString(this PlistElementArray array, string key, bool isKeepUnique) { if (!isKeepUnique) { array.AddString(key); return; } var keys = array.values.Where(x => x.AsString() == key); if (keys != null && keys.Count() != 0) { return; } array.AddString(key); }
/// <summary> /// 设置url schemes地址 /// </summary> /// <param name="plist"></param> /// <param name="urlList"></param> private static void SetURLSchemes(PlistDocument plist, List <XcodeProjectSetting.BundleUrlType> urlList) { PlistElementArray urlTypes; PlistElementDict itmeDict; if (plist.root.values.ContainsKey(XcodeProjectSetting.URL_TYPES_KEY)) { urlTypes = plist.root[XcodeProjectSetting.URL_TYPES_KEY].AsArray(); } else { urlTypes = plist.root.CreateArray(XcodeProjectSetting.URL_TYPES_KEY); } for (int i = 0; i < urlList.Count; i++) { itmeDict = urlTypes.AddDict(); itmeDict.SetString(XcodeProjectSetting.URL_TYPE_ROLE_KEY, "Editor"); itmeDict.SetString(XcodeProjectSetting.URL_IDENTIFIER_KEY, urlList[i].identifier); PlistElementArray schemesArray = itmeDict.CreateArray(XcodeProjectSetting.URL_SCHEMES_KEY); if (itmeDict.values.ContainsKey(XcodeProjectSetting.URL_SCHEMES_KEY)) { schemesArray = itmeDict[XcodeProjectSetting.URL_SCHEMES_KEY].AsArray(); } else { schemesArray = itmeDict.CreateArray(XcodeProjectSetting.URL_SCHEMES_KEY); } //TODO:按理说要排除已经存在的,但由于我们是新生成,所以不做排除 for (int j = 0; j < urlList[i].bundleSchmes.Count; j++) { schemesArray.AddString(urlList[i].bundleSchmes[j]); } } }
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; // Change value of CFBundleVersion in Xcode plist PlistElementArray schemes = rootDict.CreateArray("LSApplicationQueriesSchemes"); schemes.AddString("line"); rootDict.SetString("NSPhotoLibraryAddUsageDescription", "Save Image"); File.WriteAllText(plistPath, plist.WriteToString()); } }
static void UpdateInfoPlist(string pathToBuildProject) { // Get plist string plistPath = pathToBuildProject + "/Info.plist"; PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); //Get root PlistElementDict rootDict = plist.root; var buildKey = ""; //Toogle Gloss icon /*buildKey = "Icon already includes gloss effects"; * rootDict.SetBoolean(buildKey,true); * * buildKey = "UIRequiresFullScreen"; * rootDict.SetBoolean(buildKey,false);*/ // background location useage key (new in iOS 8) /*rootDict.SetString("NSLocationAlwaysUsageDescription", "Uses background location");*/ // Change value of CFBundleVersion in Xcode plist PlistElementArray bgModes = rootDict.CreateArray("UIBackgroundModes"); bgModes.AddString("remote-notification"); /*bgModes.AddString("location"); * bgModes.AddString("fetch");*/ File.WriteAllText(plistPath, plist.WriteToString()); }
/// <summary> /// 添加urlscheme白名单 /// </summary> /// <param name="urlScheme">URL scheme.</param> public void AddLSApplicationQueriesScheme(string urlScheme) { const string KEY = "LSApplicationQueriesSchemes"; PlistElementDict root = _plist.root; PlistElementArray urlSchemeList = root[KEY] as PlistElementArray; if (null == urlSchemeList) { urlSchemeList = root.CreateArray(KEY); } bool isInclude = false; foreach (PlistElement item in urlSchemeList.values) { if (item.AsString() == urlScheme) { isInclude = true; break; } } if (false == isInclude) { urlSchemeList.AddString(urlScheme); } }
public static void EditXcodePlist(BuildTarget buildTarget, string pathToBuiltProject) { if (buildTarget == BuildTarget.iOS) { string WEBENGAGE_LICENSE_CODE = "YOUR-WEBENGAGE-LICENSE-CODE"; string logLevel = "VERBOSE"; bool apnsAutoRegister = true; bool trackLocation = false; // Update plist string plistPath = pathToBuiltProject + "/Info.plist"; PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); PlistElementDict rootDict = plist.root; rootDict.SetString("WEGLicenseCode", WEBENGAGE_LICENSE_CODE); rootDict.SetString("WEGLogLevel", logLevel); rootDict.SetBoolean("WEGApnsAutoRegister", apnsAutoRegister); if (trackLocation) { PlistElementArray bgModes = rootDict.CreateArray("UIBackgroundModes"); bgModes.AddString("location"); // TODO: Background location useage key (new in iOS 8) //rootDict.SetString("NSLocationAlwaysUsageDescription", "Uses background location"); } // Write to Info.plist file File.WriteAllText(plistPath, plist.WriteToString()); } }
//================================================================================= //外部 //================================================================================= /// <summary> /// URL 设置URLSchemes /// </summary> public static void SetURLSchemes(string buildPath, string urlIdentifier, List <string> schemeList) { PlistDocument plist = GetInfoPlist(buildPath); //URL types 获取,新建,如果没有设置 PlistElementArray urlTypes; if (plist.root.values.ContainsKey(XcodeProjectSetting.URL_TYPES_KEY)) { urlTypes = plist.root[XcodeProjectSetting.URL_TYPES_KEY].AsArray(); } else { urlTypes = plist.root.CreateArray(XcodeProjectSetting.URL_TYPES_KEY); } PlistElementDict itmeDict; itmeDict = urlTypes.AddDict(); /* * //URL types获得在内的项目,如果不设置就创建 * if(urlTypes.values.Count == 0){ * itmeDict = urlTypes.AddDict (); * } * else{ * itmeDict = urlTypes.values[0].AsDict(); * } */ //Document Role标识 itmeDict.SetString(XcodeProjectSetting.URL_TYPE_ROLE_KEY, "Editor"); itmeDict.SetString(XcodeProjectSetting.URL_IDENTIFIER_KEY, urlIdentifier); //URL Schemesを取得、設定されていなければ作成(上書きしたい場合はif無くして、CreateArrayのみでok) PlistElementArray schemesArray = itmeDict.CreateArray(XcodeProjectSetting.URL_SCHEMES_KEY); if (itmeDict.values.ContainsKey(XcodeProjectSetting.URL_SCHEMES_KEY)) { schemesArray = itmeDict[XcodeProjectSetting.URL_SCHEMES_KEY].AsArray(); } else { schemesArray = itmeDict.CreateArray(XcodeProjectSetting.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保存 plist.WriteToFile(GetInfoPlistPath(buildPath)); }
public void AddKeychainSharing() { PlistElementArray temp = new PlistElementArray(); temp.AddString("$(AppIdentifierPrefix)" + PlayerSettings.applicationIdentifier); GetOrCreateEntitlementDoc().root[KeychainEntitlements.Key] = temp; m_Project.AddCapability(m_TargetGuid, PBXCapabilityType.KeychainSharing); }
static void EditInfoPlist(string filePath) { string path = filePath + "/Info.plist"; PlistDocument plistDocument = new PlistDocument(); plistDocument.ReadFromFile(path); PlistElementDict dict = plistDocument.root.AsDict(); // 添加白名单(add Application Queries Schemes) PlistElementArray array = dict.CreateArray("LSApplicationQueriesSchemes"); // tianmao/taobao Application Queries Schemes: array.AddString("tmall"); array.AddString("taobao"); plistDocument.WriteToFile(path); }
//在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); } }
//================================================================================= //外部 //================================================================================= /// <summary> /// URLスキームの設定。既に登録されていても重複しない /// </summary> public static void SetURLSchemes(string buildPath, string urlIdentifier, List <string> schemeList) { PlistDocument plist = GetInfoPlist(buildPath); //URL types PlistElementArray urlTypes; if (plist.root.values.ContainsKey(XcodeProjectSetting.URL_TYPES_KEY)) { urlTypes = plist.root[XcodeProjectSetting.URL_TYPES_KEY].AsArray(); } else { urlTypes = plist.root.CreateArray(XcodeProjectSetting.URL_TYPES_KEY); } //URL types PlistElementDict itmeDict; //if(urlTypes.values.Count == 0){ // itmeDict = urlTypes.AddDict (); //} //else{ // itmeDict = urlTypes.values[0].AsDict(); //} itmeDict = urlTypes.AddDict(); //Document Role itmeDict.SetString(XcodeProjectSetting.URL_TYPE_ROLE_KEY, "Editor"); itmeDict.SetString(XcodeProjectSetting.URL_IDENTIFIER_KEY, urlIdentifier); PlistElementArray schemesArray = itmeDict.CreateArray(XcodeProjectSetting.URL_SCHEMES_KEY); if (itmeDict.values.ContainsKey(XcodeProjectSetting.URL_SCHEMES_KEY)) { schemesArray = itmeDict[XcodeProjectSetting.URL_SCHEMES_KEY].AsArray(); } else { schemesArray = itmeDict.CreateArray(XcodeProjectSetting.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保存 plist.WriteToFile(GetInfoPlistPath(buildPath)); }
/// <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); } }
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); } } }
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 EditorPlist(string plistPath) { string infoPath = plistPath + "/info.plist"; PlistDocument info = new PlistDocument(); info.ReadFromString(File.ReadAllText(infoPath)); info.root.SetBoolean("ITSAppUsesNonExemptEncryption", false); info.root.SetString("NSCameraUsageDescription", "App需要使用您的相机"); info.root.SetString("NSMicrophoneUsageDescription", "App需要使用您的麦克风"); PlistElementArray addArray = info.root.CreateArray("LSApplicationQueriesSchemes"); addArray.AddString("weixin"); addArray.AddString("wechat"); addArray.AddString("wtloginmqq2"); addArray.AddString("mqqopensdkapiV3"); addArray.AddString("mqqwpa"); File.WriteAllText(infoPath, info.WriteToString()); }
public static void AddIfMissing(this PlistElementArray elementArray, string value) { if (elementArray is null) { throw new ArgumentNullException(nameof(elementArray)); } if (elementArray.values.OfType <PlistElementString>().Any(element => element.value == value) == false) { elementArray.AddString(value); } }