73.获取iOS项目名称及版本号 Build版本

获取项目名称
NSString *executableFile = [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleExecutableKey];   
版本号

NSString *bulid = [[[NSBundlemainBundle] infoDictionary]objectForKey:(NSString *)kCFBundleVersionKey];

以上方法不能得到 app_Version 只能通过下面方法


或者下面方法
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
  CFShow(infoDictionary);
// app名称
  NSString *app_Name = [infoDictionary objectForKey:@ "CFBundleDisplayName" ];
  // app版本
  NSString *app_Version = [infoDictionary objectForKey:@ "CFBundleShortVersionString" ];
  // app build版本
  NSString *app_build = [infoDictionary objectForKey:@ "CFBundleVersion" ];

最快速则为这样

[NSBundle mainBundle] objectForInfoDictionaryKey: @"CFBundleDisplayName"]

[[NSBundle mainBundle] objectForInfoDictionaryKey: @"CFBundleShortVersionString"]

[[NSBundle mainBundle] objectForInfoDictionaryKey: @"CFBundleVersion"]


在Unity中获取Xcode应用的版本号,通常需要通过间接的方式来实现,因为Unity是一个游戏引擎,它并不直接提供对iOS应用的元数据访问。但是,你可以通过打包过程中的一些预处理步骤或者使用Unity提供的插件来达到这个目的。 一种常见的做法是在构建iOS项目时,利用Shell脚本或者PostprocessBuild Player设置,在打包完成后读取Info.plist文件中的CFBundleVersion或CFBundleShortVersionString。这两个键分别包含了应用的完整版本号和简短版本号。 以下是简单的步骤: 1. 创建一个新的C#脚本,例如`GetAppVersion.cs`。 ```csharp using System.IO; using UnityEditor.iOS.Extensions; public class GetAppVersion : IPreprocessBuildPlayer { public int callbackOrder = 0; public bool isCallbackRequired = true; void OnPreprocessBuild(BuildTarget buildTarget, string path) { if (buildTarget == BuildTarget.iOS) { string infoPlistPath = Path.Combine(path, "YourProjectName", "Resources", "Info.plist"); using (var file = File.OpenRead(infoPlistPath)) { var props = new PropertyListReader(file).ToDictionary(); // 获取版本号 string versionKey = "CFBundleVersion"; if (!props.ContainsKey(versionKey)) versionKey = "CFBundleShortVersionString"; string version = props[versionKey]; Debug.Log("Application Version: " + version); } } } } ``` 2. 将此脚本拖到Assets > Create > Script文件夹下,并确保在Inspector窗口中勾选"Apply to All Scenes"。 3. 打开Player Settings,找到PostProcessBuild选项,将新创建的脚本添加到Preprocess Build Player列表中。 在实际运行游戏时,上述代码会在打包前打印出应用的版本号。请注意,你需要将`"YourProjectName"`替换为你的Unity工程的实际名称。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值