别人的代码
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 文件 就可以找到真实的 字符
标签:string,iOS,SetString,导出,framework,Unity,proj,new,plist From: https://www.cnblogs.com/unity-android-ios/p/17025616.html