private static void OnPostprocessBuildIOS(string pathToBuiltProject) { // We use UnityEditor.iOS.Xcode API which only exists in iOS editor module #if UNITY_IOS //Handle plist string plistPath = pathToBuiltProject + "/Info.plist"; PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); PlistElementDict rootDict = plist.root; rootDict.SetString("CFBundleVersion", "1.0.67"); rootDict.SetString("NSPhotoLibraryUsageDescription", "Use Photo"); rootDict.SetString("NSPhotoLibraryAddUsageDescription", "Use Photo 11"); rootDict.SetString("NSCameraUsageDescription", "Use Camera"); File.WriteAllText(plistPath, plist.WriteToString()); 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"), "CoreImage.framework", false); proj.AddFrameworkToProject(proj.TargetGuidByName("Unity-iPhone"), "Accelerate.framework", false); string target = proj.TargetGuidByName("Unity-iPhone"); Directory.CreateDirectory(Path.Combine(pathToBuiltProject, "Libraries/Unity")); 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()); CopyFile("libpaddle_capi_layers.a", pathToBuiltProject); #endif }
/// <summary> /// URLスキームを追加します /// </summary> /// <param name="path"> 出力先のパス </param> public static void AddIOSUrlScheme(string path) { #if UNITY_IOS string plistPath = Path.Combine(path, "Info.plist"); PlistDocument plist = new PlistDocument(); // 読み込み plist.ReadFromFile(plistPath); PlistElementArray urlTypeArray = plist.root.CreateArray("CFBundleURLTypes"); PlistElementDict urlTypeDict = urlTypeArray.AddDict(); PlistElementArray urlSchemeArray = urlTypeDict.CreateArray("CFBundleURLSchemes"); SDKConfiguration sdkConfiguration = UrlSchemeEditTool.LoadSDKConfiguration(); if (sdkConfiguration == null) { return; } var urlScheme = sdkConfiguration.IOSUrlScheme; var Validator = new UriSchemeValidator(urlScheme); if (!Validator.Validate()) { Debug.LogError("iOSのURLスキーマが不正なのでURLスキーマの追加処理をスキップしました"); return; } Uri uri; try { uri = new Uri(urlScheme); } catch (UriFormatException) { return; } // URLスキームを追加 urlSchemeArray.AddString(uri.Scheme); // 書き込み plist.WriteToFile(plistPath); #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)); }
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; rootDict.SetString("NSBluetoothAlwaysUsageDescription", "Uses BLE to communicate with Pixels dice."); rootDict.SetString("NSBluetoothPeripheralUsageDescription", "Uses BLE to communicate with Pixels dice."); // Write to file File.WriteAllText(plistPath, plist.WriteToString()); } }
/// <summary> /// 修改plist /// </summary> /// <param name="pathToBuildProject"></param> static void SetPlist(string pathToBuildProject) { string _plistPath = pathToBuildProject + "/Info.plist"; PlistDocument _plist = new PlistDocument(); _plist.ReadFromString(File.ReadAllText(_plistPath)); PlistElementDict _rootDic = _plist.root; _rootDic.SetString("View controller-based status bar appearance", "NO"); _rootDic.SetString("NSContactsUsageDescription", "是否允许此游戏使用麦克风?"); File.WriteAllText(_plistPath, _plist.WriteToString()); //保存plist //_plist.WriteToFile(_plistPath); }
static void SetPlist(string pathToBuildProject) { string _plistPath = pathToBuildProject + "/Info.plist"; MonoBehaviour.print("plist path:" + _plistPath); PlistDocument _plist = new PlistDocument(); _plist.ReadFromString(File.ReadAllText(_plistPath)); PlistElementDict _rootDic = _plist.root; // Add value of NSAppTransportSecurity in Xcode plist var atsKey = "NSAppTransportSecurity"; PlistElementDict dictTmp = _rootDic.CreateDict(atsKey); dictTmp.SetBoolean("NSAllowsArbitraryLoads", true); File.WriteAllText(_plistPath, _plist.WriteToString()); }
public static void ChangeXcodePlist(BuildTarget buildTarget, string pathToBuiltProject) { if (shouldRun && buildTarget == BuildTarget.iOS) { // Get plist string plistPath = pathToBuiltProject + "/" + nameOfPlist; PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); // Get root PlistElementDict rootDict = plist.root; rootDict.SetString(keyForMicrophoneUsage, microphoneUsageDescription); rootDict.SetString(keyForSpeechRecognitionUsage, speechRecognitionUsageDescription); // Write to file File.WriteAllText(plistPath, plist.WriteToString()); } }
public static void OnPostprocessBuild(BuildTarget buildTarget, string buildPath) { #if UNITY_IPHONE // Get plist string plistPath = buildPath + "/Info.plist"; PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); // Get root PlistElementDict rootDict = plist.root; // Add remote-notification Xcode plist.info var buildKey = "UIBackgroundModes"; rootDict.CreateArray(buildKey).AddString("remote-notification"); // Write to plist File.WriteAllText(plistPath, plist.WriteToString()); #endif }
private static void OnPostProcessBuild(BuildTarget target, string path) { #if UNITY_IOS string plistPath = path + "/Info.plist"; PlistDocument plist = new PlistDocument(); plist.ReadFromFile(plistPath); PlistElementDict rootDict = plist.root; string usageDescription = "For beacon detection"; rootDict.SetString("NSLocationUsageDescription", usageDescription); rootDict.SetString("NSLocationAlwaysUsageDescription", usageDescription); // iOS 11 rootDict.SetString("NSLocationAlwaysAndWhenInUseUsageDescription", usageDescription); rootDict.SetString("NSLocationWhenInUseUsageDescription", usageDescription); // Write to file plist.WriteToFile(plistPath); #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; // Change NSFaceId Description rootDict.SetString(KEY_FACEID, KEY_FACEID_DESCRIPTION); // Write to file File.WriteAllText(plistPath, plist.WriteToString()); } }
public static void OnPostProcessBuild(BuildTarget target, string path) { if (target != BuildTarget.iOS) { return; } string plistPath = Path.Combine(path, "Info.plist"); PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); PlistElementDict rootDict = plist.root; rootDict.SetString("NSPhotoLibraryUsageDescription", "Requires access to the Photo Library"); rootDict.SetString("NSPhotoLibraryAddUsageDescription", "Requires access to the Photo Library"); File.WriteAllText(plistPath, plist.WriteToString()); }
MotionUsageDescription = @"Allow this app to use the pedometer."; // Change this as necessary void IPreprocessBuild.OnPreprocessBuild(BuildTarget target, string path) { #if UNITY_ANDROID // Create the Android plugins directory Directory.CreateDirectory(AndroidPlugins); // Copy the manifest into it // This is the only place where Unity picks up manifests, so we have to copy into it File.Copy(Path.Combine(Environment.CurrentDirectory, "Assets/Pedometer/Plugins/Android/AndroidManifest.xml"), Path.Combine(AndroidPlugins, "AndroidManifest.xml")); #elif UNITY_IOS // Get the property list string plistPath = path + "/Info.plist"; PlistDocument plist = new PlistDocument(); // Read it plist.ReadFromString(File.ReadAllText(plistPath)); PlistElementDict rootDictionary = plist.root; // Add the motion usage description rootDictionary.SetString(MotionUsageKey, MotionUsageDescription); File.WriteAllText(plistPath, plist.WriteToString()); #endif }
public void OnPostprocessBuild(BuildTarget target, string path) { if (target == BuildTarget.iOS) { Debug.Log("XCodePostProcessBuild.OnPostprocessBuild for target " + target + " at path " + path); // edit project file var projectPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj"; PBXProject pbxProject = new PBXProject(); pbxProject.ReadFromFile(projectPath); string targetGuid = pbxProject.GetUnityFrameworkTargetGuid(); string frameworkGuid = pbxProject.GetUnityFrameworkTargetGuid(); // disable bitcode because the gRPC library does not have bitcode // remove when using a gRPC library containing bitcode pbxProject.SetBuildProperty(targetGuid, "ENABLE_BITCODE", "NO"); pbxProject.SetBuildProperty(frameworkGuid, "ENABLE_BITCODE", "NO"); // include libz to support gRPC compression pbxProject.AddFrameworkToProject(frameworkGuid, "libz.tbd", false); // include Safari Framework to support embedded Safari Login/Logout pbxProject.AddFrameworkToProject(frameworkGuid, "SafariServices.framework", false); pbxProject.WriteToFile(projectPath); // edit plist file string plistPath = path + "/Info.plist"; PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); PlistElementDict rootDict = plist.root; // remove exit on suspend if it exists string exitsOnSuspendKey = "UIApplicationExitsOnSuspend"; if (rootDict.values.ContainsKey(exitsOnSuspendKey)) { rootDict.values.Remove(exitsOnSuspendKey); } File.WriteAllText(plistPath, plist.WriteToString()); } }
public static void OnPostprocessBuild(BuildTarget buildTarget, string path) { // Read plist var plistPath = Path.Combine(path, "Info.plist"); var plist = new PlistDocument(); plist.ReadFromFile(plistPath); // Update value //if(usesCamera) { PlistElementDict rootDict = plist.root; rootDict.SetString("NSCameraUsageDescription", cameraUsage); //} // Write plist 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; rootDict.SetString("NSUserTrackingUsageDescription", "Please let me use IDFA"); addSKAdNetworkIDs(rootDict); // Write to file File.WriteAllText(plistPath, plist.WriteToString()); } }
private static void _modifyPlist(string path) { //Info.plist string plistPath = path + "/Info.plist"; PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); //ROOT PlistElementDict rootDict = plist.root; //执行修改操作 //设置使用简体中文 rootDict.SetString("CFBundleDevelopmentRegion", "zh_CN"); //iOS 10 设置使用权限说明 //摄像机权限 rootDict.SetString("NSCameraUsageDescription", "App需要您的同意,才能使用相机"); //摄像机权限 rootDict.SetString("NSPhotoLibraryUsageDescription", "App需要您的同意,才能访问相册"); ////定位权限 rootDict.SetString("NSLocationWhenInUseUsageDescription", "App需要您的同意,才能获取位置信息"); ////录音权限 //rootDict.SetString("NSMicrophoneUsageDescription", "VoiceChat"); ////添加第三方应用的 URL Scheme 到白名单 //PlistElementArray LSApplicationQueriesSchemes = rootDict.CreateArray("LSApplicationQueriesSchemes"); ////微信 //LSApplicationQueriesSchemes.AddString("weixin"); //PlistElementArray urlTypes = rootDict.CreateArray("CFBundleURLTypes"); ////添加自己应用的 URL Scheme ////网页唤起 //PlistElementDict webUrl = urlTypes.AddDict(); //webUrl.SetString("CFBundleTypeRole", "Editor"); //webUrl.SetString("CFBundleURLName", "web"); //PlistElementArray webUrlScheme = webUrl.CreateArray("CFBundleURLSchemes"); //webUrlScheme.AddString("productname"); //换成自己的产品名 //写入 File.WriteAllText(plistPath, plist.WriteToString()); }
private static void BuildForiOS(string path, UMPSettings settings) { #if UNITY_IPHONE var projPath = Path.Combine(path, "Unity-iPhone.xcodeproj/project.pbxproj"); var pbxProject = new PBXProject(); pbxProject.ReadFromString(File.ReadAllText(projPath)); #if UNITY_2019_3_OR_NEWER var target = pbxProject.GetUnityFrameworkTargetGuid(); #else var target = pbxProject.TargetGuidByName(PBXProject.GetUnityTargetName()); #endif // Activate Background Mode for Audio string plistPath = path + "/Info.plist"; PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); PlistElementDict rootDict = plist.root; var buildKey = "UIBackgroundModes"; rootDict.CreateArray(buildKey).AddString("audio"); File.WriteAllText(plistPath, plist.WriteToString()); var fileGuid = pbxProject.AddFile("usr/lib/" + "libc++.dylib", "Frameworks/" + "libc++.dylib", PBXSourceTree.Sdk); pbxProject.AddFileToBuild(target, fileGuid); fileGuid = pbxProject.AddFile("usr/lib/" + "libz.dylib", "Frameworks/" + "libz.dylib", PBXSourceTree.Sdk); pbxProject.AddFileToBuild(target, fileGuid); fileGuid = pbxProject.AddFile("usr/lib/" + "libz.tbd", "Frameworks/" + "libz.tbd", PBXSourceTree.Sdk); pbxProject.AddFileToBuild(target, fileGuid); fileGuid = pbxProject.AddFile("usr/lib/" + "libbz2.dylib", "Frameworks/" + "libbz2.dylib", PBXSourceTree.Sdk); pbxProject.AddFileToBuild(target, fileGuid); fileGuid = pbxProject.AddFile("usr/lib/" + "libbz2.tbd", "Frameworks/" + "libbz2.tbd", PBXSourceTree.Sdk); pbxProject.AddFileToBuild(target, fileGuid); if ((settings.PlayersIPhone & PlayerOptionsIPhone.PlayerTypes.Native) == PlayerOptionsIPhone.PlayerTypes.Native) { pbxProject.AddFrameworkToProject(target, "CoreImage.framework", true); } File.WriteAllText(projPath, pbxProject.WriteToString()); #endif }
public static void ChangeXcodePlist(BuildTarget buildTarget, string pathToBuiltProject) { // 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 = "NFCReaderUsageDescription"; rootDict.SetString(buildKey, "Not Used."); // Write to file File.WriteAllText(plistPath, plist.WriteToString()); }
private static void DoAddSKAdNetworkItemsToInfo(string projectPath) { string infoPlistPath = Path.Combine(projectPath, "Info.plist"); PlistDocument plistDoc = new PlistDocument(); plistDoc.ReadFromFile(infoPlistPath); if (plistDoc.root != null) { PlistElementDict rootDict = plistDoc.root; PlistElement elementSKAdNetworkItems = rootDict["SKAdNetworkItems"]; if (null == elementSKAdNetworkItems) { rootDict["SKAdNetworkItems"] = new PlistElementArray(); elementSKAdNetworkItems = rootDict["SKAdNetworkItems"]; } else { PlistElementArray arrayAdNetworkItems = elementSKAdNetworkItems.AsArray(); int count = arrayAdNetworkItems.values.Count; arrayAdNetworkItems.values.RemoveRange(0, count); } PlistElementArray arrayItems = elementSKAdNetworkItems.AsArray(); PlistElementArray addAdNetworks = DoGetAdNetworks(); for (int i = 0; i < addAdNetworks.values.Count; i++) { PlistElementDict item = addAdNetworks.values[i] as PlistElementDict; arrayItems.values.Add(item); } plistDoc.WriteToFile(infoPlistPath); } else { Debug.LogError("Error: Can't open " + infoPlistPath); } }
public static void OnPostprocessBuild( BuildTarget target, string buildPath ) { if( !ENABLED ) return; if( target == BuildTarget.iOS ) { string plistPath = Path.Combine( buildPath, "Info.plist" ); PlistDocument plist = new PlistDocument(); plist.ReadFromString( File.ReadAllText( plistPath ) ); PlistElementDict rootDict = plist.root; rootDict.SetString( "NSPhotoLibraryUsageDescription", PHOTO_LIBRARY_USAGE_DESCRIPTION ); rootDict.SetString( "NSPhotoLibraryAddUsageDescription", PHOTO_LIBRARY_USAGE_DESCRIPTION ); File.WriteAllText( plistPath, plist.WriteToString() ); } }
public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject) { if (target != BuildTarget.iOS) { return; } string plistPath = pathToBuiltProject + "/Info.plist"; PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); PlistElementDict rootDict = plist.root; SetupURLScheme(rootDict); SetupQueriesSchemes(rootDict); File.WriteAllText(plistPath, plist.WriteToString()); }
private static void OnPostprocessBuild(BuildTarget target, string pathToBuildProject) { AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate); string _projPath = PBXProject.GetPBXProjectPath(pathToBuildProject); PBXProject project = new PBXProject(); project.ReadFromString(File.ReadAllText(_projPath)); string targetGuid = project.TargetGuidByName("Unity-iPhone"); project.AddFrameworkToProject(targetGuid, "CFNetwork.framework", false); project.AddFrameworkToProject(targetGuid, "CoreTelephony.framework", false); project.AddFrameworkToProject(targetGuid, "Security.framework", false); project.AddFrameworkToProject(targetGuid, "SystemConfiguration.framework", false); project.AddFrameworkToProject(targetGuid, "Security.framework", false); project.AddFrameworkToProject(targetGuid, "AdSupport.framework", false); project.AddFrameworkToProject(targetGuid, "CoreLocation.framework", false); project.AddFileToBuild(targetGuid, project.AddFile("usr/lib/libc++.tbd", "libc++.tbd", PBXSourceTree.Sdk)); project.AddFileToBuild(targetGuid, project.AddFile("usr/lib/libsqlite3.0.tbd", "libsqlite3.0.tbd", PBXSourceTree.Sdk)); project.AddFileToBuild(targetGuid, project.AddFile("usr/lib/libz.tbd", "libz.tbd", PBXSourceTree.Sdk)); project.SetBuildProperty(targetGuid, "ENABLE_BITCODE", "NO"); project.SetBuildProperty(targetGuid, "LOCATION_UPDATES", "YES"); project.WriteToFile(_projPath); // plist string plistPath = pathToBuildProject + "/Info.plist"; PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); PlistElementDict rootDict = plist.root; PlistElementDict dictTmp = rootDict.CreateDict("NSAppTransportSecurity"); dictTmp.SetBoolean("NSAllowsArbitraryLoads", true); // 保存plist plist.WriteToFile(plistPath); Log.Debug("完成IOS工程配置"); }
public static void ChangeXcodePlist(BuildTarget _buildTarget, string pathToBuiltProject) { // Checks if building for iOS if (_buildTarget == BuildTarget.iOS) { // Get plist string path = pathToBuiltProject + "/Info.plist"; PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(path)); // Get root PlistElementDict rootDict = plist.root; rootDict.SetBoolean("UIFileSharingEnabled", true); // Write to file File.WriteAllText(path, plist.WriteToString()); } }
private void SetDataForKey(object key, object value, PlistElementDict elementDict) { if (value is int) { elementDict.SetInteger(key.ToString(), Convert.ToInt32(value)); } else if (value is bool) { elementDict.SetBoolean(key.ToString(), Convert.ToBoolean(value)); } else if (value is string) { elementDict.SetString(key.ToString(), value.ToString()); } else if (value is float) { elementDict.SetReal(key.ToString(), Convert.ToSingle(value)); } }
public static void OnPostprocessBuild(BuildTarget BuildTarget, string path) { if (BuildTarget == BuildTarget.iOS) { // 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 NSMicrophoneUsageDescription in Xcode plist rootDict.SetString("NSMicrophoneUsageDescription", "喵喵喵喵喵喵???"); // Write to file File.WriteAllText(plistPath, plist.WriteToString()); } }
private static void ChangeXcodePlist(BuildTarget buildTarget, string pathToBuiltProject) { // Get plist string plistPath = pathToBuiltProject + "/Info.plist"; PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); // Get root PlistElementDict rootDict = plist.root; // Set value of NSLocationAlwaysUsageDescription in Xcode plist var buildKey = "NSLocationAlwaysUsageDescription"; rootDict.SetString(buildKey, "Just to show "); // Write to file File.WriteAllText(plistPath, plist.WriteToString()); }
public static void ChangeXcodePlist(BuildTarget buildTarget, string pathToBuiltProject) { // Adds UIFileSharingEnabled to Info.plist if (buildTarget == BuildTarget.iOS && CloudTestPipeline.IsRunningOnCloud()) { // Get plist string plistPath = pathToBuiltProject + "/Info.plist"; PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); // Get root PlistElementDict rootDict = plist.root; rootDict.SetBoolean("UIFileSharingEnabled", true); // rootDict.SetString("CFBundleDisplayName", "CloudBundle"); // Write to Info.plist Debug.Log("Updating Info.plist"); File.WriteAllText(plistPath, plist.WriteToString()); } }
private static void onPostProcessBuildPlayer(BuildTarget buildTarget, string path) { #if UNITY_IOS || UNITY_TVOS if (buildTarget == BuildTarget.iOS) { //string entitlementFileName = "greedubunnies_dev_pushnotifications.entitlement"; //string entitlementPath = "Apple Certificates/" + entitlementFileName; //CopyAndReplaceFile(entitlementPath, Path.Combine(path , entitlementFileName)); //string xcodeprojPath = path + "/Unity-iPhone.xcodeproj"; //string projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj"; //PBXProject proj = new PBXProject(); //proj.ReadFromString(File.ReadAllText(projPath)); //string target = proj.TargetGuidByName("Unity-iPhone"); //proj.AddFrameworkToProject(target, "UserNotifications.framework", false); //proj.AddFrameworkToProject(target, "StoreKit.framework", false); //proj.AddCapability(target, PBXCapabilityType.PushNotifications, entitlementFileName); //File.WriteAllText(projPath, proj.WriteToString()); // Update info.plist // Get plist string plistPath = path + "/Info.plist"; PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); // Get plist root PlistElementDict rootDict = plist.root; //rootDict.SetString("NSLocationWhenInUseUsageDescription", "Location used to inform you when doctor/client is here."); rootDict.SetString("NSCameraUsageDescription", "Camera is used to scan QR code."); // enablde background mode for remote notifications //var buildKey = "UIBackgroundModes"; //rootDict.CreateArray(buildKey).AddString("remote-notification"); // Write to file File.WriteAllText(plistPath, plist.WriteToString()); } #endif }
public static void OnPostProcessBuild(BuildTarget target, string path) { #if UNITY_IPHONE if (target != BuildTarget.iOS) { return; } string projPath = Path.Combine(path, "Unity-iPhone.xcodeproj/project.pbxproj"); // automatically @include frameworks and disable bitcode PBXProject proj = new PBXProject(); string file = File.ReadAllText(projPath); proj.ReadFromString(file); #if UNITY_2019_3_OR_NEWER string targetGuid = proj.GetUnityFrameworkTargetGuid(); #else string targetGuid = proj.TargetGuidByName(PBXProject.GetUnityTargetName()); #endif proj.SetBuildProperty(targetGuid, "CLANG_ENABLE_MODULES", "YES"); proj.SetBuildProperty(targetGuid, "ENABLE_BITCODE", "NO"); File.WriteAllText(projPath, proj.WriteToString()); // add necessary permissions to Plist string plistPath = Path.Combine(path, "Info.plist"); PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); PlistElementDict rootDict = plist.root; rootDict.SetString("NSPhotoLibraryUsageDescription", "Requires access to the Photo Library"); rootDict.SetString("NSPhotoLibraryAddUsageDescription", "Requires access to the Photo Library"); rootDict.SetString("NSCameraUsageDescription", "Requires access to the Camera"); rootDict.SetString("NSContactsUsageDescription", "Requires access to Contacts"); rootDict.SetString("NSLocationAlwaysUsageDescription", "Requires access to Location"); rootDict.SetString("NSLocationWhenInUseUsageDescription", "Requires access to Location"); rootDict.SetString("NSLocationAlwaysAndWhenInUseUsageDescription", "Requires access to Location"); File.WriteAllText(plistPath, plist.WriteToString()); #endif }
public static void OnPostprocessBuild(BuildTarget target, string buildPath) { if (!ENABLED) { return; } if (target == BuildTarget.iOS) { string pbxProjectPath = PBXProject.GetPBXProjectPath(buildPath); string plistPath = Path.Combine(buildPath, "Info.plist"); PBXProject pbxProject = new PBXProject(); pbxProject.ReadFromFile(pbxProjectPath); string targetGUID = pbxProject.TargetGuidByName(PBXProject.GetUnityTargetName()); if (MINIMUM_TARGET_8_OR_ABOVE) { pbxProject.AddBuildProperty(targetGUID, "OTHER_LDFLAGS", "-framework Photos"); pbxProject.AddBuildProperty(targetGUID, "OTHER_LDFLAGS", "-framework MobileCoreServices"); } else { pbxProject.AddBuildProperty(targetGUID, "OTHER_LDFLAGS", "-weak_framework Photos"); pbxProject.AddBuildProperty(targetGUID, "OTHER_LDFLAGS", "-framework AssetsLibrary"); pbxProject.AddBuildProperty(targetGUID, "OTHER_LDFLAGS", "-framework MobileCoreServices"); } pbxProject.RemoveFrameworkFromProject(targetGUID, "Photos.framework"); File.WriteAllText(pbxProjectPath, pbxProject.WriteToString()); PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); PlistElementDict rootDict = plist.root; rootDict.SetString("NSPhotoLibraryUsageDescription", PHOTO_LIBRARY_USAGE_DESCRIPTION); rootDict.SetString("NSPhotoLibraryAddUsageDescription", PHOTO_LIBRARY_USAGE_DESCRIPTION); File.WriteAllText(plistPath, plist.WriteToString()); } }