别人的代码

xcode打包部分设置的脚本如下

public class XcodeSetting : MonoBehaviour
{
private static List<Menu> menuList; [PostProcessBuild(999)]
public static void OnPostprocessBuild(BuildTarget BuildTarget, string path)
{
if (BuildTarget == BuildTarget.iOS)
{
Debug.Log("OnPostprocessBuild ProjectPath:" + path);
string projPath = PBXProject.GetPBXProjectPath(path);//获取.xcodeproj文件的路径 PBXProject proj = new PBXProject();//new()一个PBXProject对象,然后从上面获取的路径中读出字符串。
string contents = File.ReadAllText(projPath);
proj.ReadFromString(contents); string target = proj.TargetGuidByName(PBXProject.GetUnityTargetName());//获取targetGUID // 链接器
proj.SetBuildProperty(target, "ENABLE_BITCODE", "NO");//bitcode是被编译程序的一种中间形式的代码。包含bitcode配置的程序将会在App store上被编译和链接。bitcode允许苹果在后期重新优化我们程序的二进制文件(我们第三方库不一定支持,所以要设置为NO)
proj.SetBuildProperty (target, "OTHER_LDFLAGS", "-Objc -all_load -lstdc++.6.0.9 -lsqlite3");//Other Linker Flags 在ios开发过程中,有时候会用到第三方的静态库(.a文件),然后导入后发现编译正常但运行时会出现selector not recognized的错误,从而导致app闪退。 //pbxProj.AddBuildProperty(targetGuid, "FRAMEWORK_SEARCH_PATHS", "$(SRCROOT)/Libraries/BabyFrameWork/**");
//pbxProj.AddBuildProperty(targetGuid, "HEADER_SEARCH_PATHS", "$(SRCROOT)/Libraries/BabyFrameWork/**");
//pbxProj.AddBuildProperty(targetGuid, "LIBRARY_SEARCH_PATHS", "$(SRCROOT)/Libraries/BabyFrameWork/**");
//------------------------拷贝系统Framework----------------------------------------------
string xcodePath = Application.dataPath + "/xcode.txt";
xcodePath = xcodePath.Replace("Assets/", "");
FileStream xcode_fs = new FileStream(xcodePath, FileMode.Open, FileAccess.Read);
StreamReader xcode_sr = new StreamReader(xcode_fs);//仅 对文本 执行 读写操作
string line = null;
while((line= xcode_sr.ReadLine())!= null)
{
Debug.Log ("framework=" + line);
string frameWorkName = line.Split('.')[0];
string filterName = line.Split ('.') [1];
if (filterName == "framework") {
if(frameWorkName == "JavaScriptCore")
{
proj.AddFrameworkToProject(target, line, true);//这里第一个参数是第三部中获取到的GUID,第二个参数是framework名(这里一定要是.framework为后缀),第三个参数是用来设置framework是require还是optional。
}
else
{
proj.AddFrameworkToProject(target, line, false);//这里第一个参数是第三部中获取到的GUID,第二个参数是framework名(这里一定要是.framework为后缀),第三个参数是用来设置framework是require还是optional。
}
}
else
{
proj.AddFileToBuild (target, proj.AddFile("usr/lib/"+line, "Frameworks/"+line, PBXSourceTree.Sdk));
}
}
//C#读取TXT文件之关上文件,留心顺序,先对文件内部执行 关上,然后才是文件~
xcode_sr.Close();
xcode_fs.Close();
//--------------------------拷贝系统Framework end------------------------------------- File.WriteAllText(projPath, proj.WriteToString()); //------------------------------APPID-----------------------------------------------------
string txtPath = Application.dataPath + "/Resources/AppId.txt";
FileStream fs = new FileStream(txtPath, FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(fs);//仅 对文本 执行 读写操作
int AppId = int.Parse(sr.ReadToEnd());
//C#读取TXT文件之关上文件,留心顺序,先对文件内部执行 关上,然后才是文件~
sr.Close();
fs.Close(); menuList = ExcelAccess.SelectMenuTable(1, AppId);
if (menuList != null)
{
if (menuList.Count > 0)
{
Menu menu = menuList[0]; string wxAppid = menu.WXAppID;
PlistElementDict dict; //UrlType
//Handle plist
string plistPath = path + "/Info.plist";
PlistDocument plist = new PlistDocument();
plist.ReadFromString(File.ReadAllText(plistPath));
PlistElementDict rootDict = plist.root; //NSContactsUsageDescription->通讯录
//NSMicrophoneUsageDescription->麦克风
//NSPhotoLibraryUsageDescription->相册
//NSCameraUsageDescription->相机
//NSLocationAlwaysUsageDescription->地理位置
//NSLocationWhenInUseUsageDescription->地理位置
rootDict.SetString("NSLocationAlwaysUsageDescription", "地理位置相近的玩家不可进入同一个牌桌");
rootDict.SetString("NSLocationUsageDescription", "地理位置相近的玩家不可进入同一个牌桌");
rootDict.SetString("NSLocationWhenInUseUsageDescription", "地理位置相近的玩家不可进入同一个牌桌");
rootDict.SetString("NSMicrophoneUsageDescription", "使用麦克风");
rootDict.SetString("NSPhotoLibraryUsageDescription", "使用相册");
rootDict.SetString("NSPhotoLibraryAdditionsUsageDescription","需要访问您的相册"); //PList文件添加微信为白名单
PlistElementArray array = rootDict.CreateArray("LSApplicationQueriesSchemes");
array.AddString("weixin"); // 设置支持HTTP
dict = rootDict.CreateDict("NSAppTransportSecurity");
dict.SetBoolean("NSAllowsArbitraryLoads", true); PlistElementArray urlTypes = rootDict.CreateArray("CFBundleURLTypes");
// add weixin url scheme应用需要在“Info.plist”中将要使用的URL Schemes列为白名单,才可正常检查其他应用是否安装。
PlistElementDict wxUrl = urlTypes.AddDict();
wxUrl.SetString("CFBundleTypeRole", "Editor");
wxUrl.SetString("CFBundleURLName", "weixin");
PlistElementArray wxUrlScheme = wxUrl.CreateArray("CFBundleURLSchemes");
wxUrlScheme.AddString(wxAppid); //add csmj url scheme
PlistElementDict appUrl = urlTypes.AddDict();
appUrl.SetString("CFBundleTypeRole", "Editor");
appUrl.SetString("CFBundleURLName", "chaoshanmajiang");
PlistElementArray appUrlScheme = appUrl.CreateArray("CFBundleURLSchemes");
appUrlScheme.AddString("elephant"+ menu.ID); //add location appkey url scheme
PlistElementDict locationUrl = urlTypes.AddDict();
locationUrl.SetString("CFBundleTypeRole", "Editor");
locationUrl.SetString("CFBundleURLName", "locationAppKey");
PlistElementArray locationScheme = locationUrl.CreateArray("CFBundleURLSchemes");
locationScheme.AddString("xx"+menu.Location_AppKey); File.WriteAllText(plistPath, plist.WriteToString());
}
} CopyAndReplaceIcon (path);
}
} static void CopyAndReplaceIcon (string projectPath)
{
string targetWXShareIconPath = projectPath + "/SDK/WX/res2.png";
string sourceIconPath = System.Environment.CurrentDirectory + "/Assets/Art/ICON/IOS/57.png";
Debug.Log (string.Format ("CopyAndReplaceIcon from {0} to {1}", sourceIconPath, targetWXShareIconPath));
File.Copy (sourceIconPath, targetWXShareIconPath, true);
}
}

我的代码

#if UNITY_IOS
using System.IO;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.iOS.Xcode; internal static class XCodePostProcess
{
[PostProcessBuild(700)]
public static void OnPostProcessBuild(
BuildTarget target, string pathToBuiltProject)
{
if (target != BuildTarget.iOS)
{
return;
} var projPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj";
var proj = new PBXProject();
proj.ReadFromFile(projPath);
var targetGUID = "";
#if UNITY_2019_3_OR_NEWER
targetGUID = proj.GetUnityFrameworkTargetGuid();
#else
targetGUID = proj.TargetGuidByName("Unity-iPhone");
#endif
proj.AddBuildProperty(targetGUID, "OTHER_LDFLAGS", "-ObjC");
proj.SetBuildProperty(targetGUID, "ENABLE_BITCODE", "NO"); // framework to project
proj.AddFrameworkToProject(targetGUID, "WebKit.framework", false);
proj.AddFrameworkToProject(targetGUID, "VideoToolbox.framework", false); proj.WriteToFile(projPath); var path = pathToBuiltProject + "/Info.plist";
var plist = new PlistDocument();
plist.ReadFromFile(path);
var root = plist.root;
root.SetString("NSUserTrackingUsageDescription", "请允许获取您的广告标识权限,您的数据将被用于追踪、分析测评广告效果,以便后续推送更好的个性化服务。");
root.SetString("NSCameraUsageDescription","是否允许此App访问你的相机进行拍照?");
root.SetString("NSPhotoLibraryUsageDescription", "是否允许此App访问你的相册?把注册的账号和密码保存到相册中,当您忘记账号和密码可在相册中找回");
root.SetString("NSPhotoLibraryAddUsageDescription", "是否允许此App访问你的相册?把注册的账号和密码保存到相册中,当您忘记账号和密码可在相册中找回"); var urlArray = root.CreateArray("CFBundleURLTypes");
PlistElementDict plistElement = new PlistElementDict();
plistElement.SetString("CFBundleTypeRole", "Editor");
//plistElement.SetString("URL identifier", "");
urlArray.values.Add(plistElement);
var items = plistElement.CreateArray("CFBundleURLSchemes"); PlistElementString it = new PlistElementString("item 0");
it.value = "com.wzhx.sgbxdios";
items.values.Add(it); plist.WriteToFile(path);
}
} #endif

很多字符是设置和显示不一样具体是啥  NSUserTrackingUsageDescription 可以先在Xcode 中设置好,然后用文本编辑器查看 info.list 文件 就可以找到真实的 字符

Unity 导出设置iOS 项目的更多相关文章

  1. Unity导出的Xcode项目,iOS端管理摄像头的方法

    Vuforia导出的工程中管理摄像头问题 在以前的篇幅中提到了unity端和iOS端的动态交互.现在出现了一个问题.因为设备上的摄像机是实例化过来的.并且是一个单例.unity虽然已经不再显示了.但是 ...

  2. Unity 导出的android项目自动生成Private Libraries

    如果Unity里面Plugins/Android 添加了 jar 文件,则导出Android 项目时会自动生成 Private Libraries. 而且里面的项还删不掉 然后在网上搜了一下,找到了原 ...

  3. 【原】设置iOS项目BuildVersion自动增加

    一.概念阐述:Build与Version的区别 在iOS中有两种“版本号”,也就是所谓的version号与build号,如下图所示: 我们用最简洁的语言来区分这两个版本号的区别以及用途如下: Vers ...

  4. 设置iOS项目BuildVersion自动增加-备用

    一.概念阐述:Build与Version的区别 在iOS中有两种“版本号”,也就是所谓的version号与build号,如下图所示: 我们用最简洁的语言来区分这两个版本号的区别以及用途如下: Vers ...

  5. 将Unity导出的Eclipse工程转换为AndroidStudio工程

    步骤:1)将unity项目导出到文件夹: 转换到安卓平台,这里只勾选google android project.然后导出到自己新建的文件夹. 2)打开导出的文件夹,看到如下内容.这是unity5.x ...

  6. Unity导出Gradle工程给Android Studio使用

    1 Unity导出Gradle项目 Unity打包时Build System选择Gradle,勾选Export Project 2 Android Studio导入Unity导出的Gradle项目 打 ...

  7. iOS将Unity导出的Xcode工程导入到另一个Xcode项目, 及常见报错的解决方法

    demo下载地址 http://pan.baidu.com/s/1pLcpKpl 1.Unity导出工程时设置bundle id要与项目一致 2.修改bit code为NO 3.删除Main.stor ...

  8. unity导出工程导入到iOS原生工程中详细步骤

    一直想抽空整理一下unity原生工程导入iOS原生工程中的详细步骤.做iOS+vuforia+unity开发这么长时间了.从最初的小小白到现在的小白.中间趟过了好多的坑.也有一些的小小收货.做一个喜欢 ...

  9. React Native(ios)项目中logo,启动屏设置

    由于logo和启动屏尺寸多,react native(ios)中没有命令可以自动生成各种的尺寸,所以可以使用以下办法:在ionic项目中生成(使用命令:ionic resources)后,再粘贴到re ...

  10. Unity iOS 项目的一种性能评测方法

    [Unity iOS 项目的一种性能评测方法]

随机推荐

  1. tensorboard 2.0可视化 —浏览器中输入http://ip:6006 - 无法访问此网站——有效解决

    https://blog.csdn.net/sinat_28442665/article/details/108975276

  2. 一些开源软件的LOGO

    整理一些开源软件的logo或者吉祥物,主要是一些以动物形象为主的logo. 1. GNU,不是一个软件,而是一个软件组织,包括很多知名的软件例如GCC编译器. GNU的LOGO是一只牛. GCC的lo ...

  3. mysql在windows下安装

    参考博客:https://blog.csdn.net/weixin_43423484/article/details/124408565

  4. ISTQB软件测试初级认证模拟题

    参考地址 http://www.docin.com/p-297467364.html 第一章:软件测试基础(18%) 1.学习目标 1.1 为什么需要软件测试? (K2) ① 通过具体的例子,来描述软 ...

  5. C++ primer笔记 -标准库类型

    最重要的两个标准库类型:string和vector string 类型的输入操作符: 1.读取并忽略开头所有的空白符 2.读取字符直至再次遇到空白字符,读取终止 string对象的基本操作: stri ...

  6. 给定一个包括 n 个整数的数组 nums 和 一个目标值 target。找出 nums 中的三个整数,使得它们的和与 target 最接近。返回这三个数的和。假定每组输入只存在唯一答案

    var threeSumClosest = function(nums, target) { let ans = nums[0] + nums[1] + nums[2]; const len = nu ...

  7. ElementUI实现手动上传

    在做项目中,与同事遇到问题,顺手记录一下 <template> <div class="common-layout"> <el-button size ...

  8. Python 字典类型

    1.由于字典中的 key 是非常关键的数据,而且程序需要通过 key 来访问 value,因此字典中的 key 不允许重复.程序既可使用花括号语法来创建字典,也可使用 dict() 函数来创建字典.实 ...

  9. 2022-04-24内部群每日三题-清辉PMP

    1.在估算项目成本时,项目经理与一位主题专家(SME)合作,该专家曾有低估交付项目需求所需工作的历时.然而,在所有其他领域,该主题专家是一位很好的贡献者,备受尊重,并且经常有相关方需要他.若要主动减轻 ...

  10. 苹果Macbook快捷键使用大全

    苹果电脑Macbook快捷键如何使用?很多小伙伴经常询问小编有关于苹果电脑的相关问题,其实很多快捷键都可以提高生产力,那么接下来一起看看苹果Macbook快捷键使用大全! 苹果电脑Macbook快捷键 ...