别人的代码

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. CSS入门学习笔记

    CSS入门学习笔记一.CSS简介1.什么是CSS?2.为什么使用CSS?3.CSS的作用二.CSS语法1.CSS基础语法2.CSS注释语法3.CSS应用方法三.CSS选择器1.元素选择器2.类选择器3 ...

  2. excel 巧用功能

    1. 分类汇总 数据-->分类汇总--> 解决问题:解决了我按字段分类并分页打印的问题,例如几十个村数据,要按村分页打印相关数据这时不能把村分别复制粘贴到一个一个工作薄,太麻烦了. 处理方 ...

  3. android 打包任务在gradle中

    //打包任务task makexxxxxxJar(type: Jar) { //指定生成的jar名 baseName xxxxxx //从哪里打包class文件 from('build/interme ...

  4. 用xlutils.copy写入中文的问题

    用xlutils.copy 将中文写入excel文档中 遇到的问题1: Traceback:Traceback (most recent call last):File "C:\Users\ ...

  5. 一 MySQL的架构与历史1.1--1.4

    1.1 MySQL逻辑架构 最上层的服务并不是 MySQL 所独有的,大多数基于网络的客户端/服务器的工具或者服务都有类似的架构.比如连接处理.授权认证.安全等等. 第二层架构是MySQL比较有意思的 ...

  6. 查询dockerhub中某镜像所有版本

    curl https://registry.hub.docker.com/v1/repositories/${imagename}/tags | tr -d '[[]" ]' | tr '} ...

  7. SpringCloud组件:搭建Eureka服务注册中心,搭建的时候一定要确保springboot和springCloud的版本对应

    搭建的时候一定要确保springboot和springCloud的版本对应,不然会报下面的错 查看版本对应得地址:https://start.spring.io/actuator/info 改了对应得 ...

  8. react backend and frontend download file

    import {  View as ViewFile} from '@/api/SafetyRule'; const Handler_DownLoadFile = (Id:number,IsEngli ...

  9. xshell he xftp下载网址

    https://www.xshell.com/zh/free-for-home-school/

  10. JS学习-async/await

    async/await 它保证函数的返回值为 promise. 用更少的.then()块来封装代码,同时它看起来很像同步代码 注意:可能会因为大量await的promises相继发生而变慢. asyn ...