Plist获取版本号等

在项目中,很多的属性都是在plist文件中设置的,在开发过程中,经常会需要获取这些属性值,下面是获取plist属性值的方法

NSDictionary *bundleDic = [[NSBundle mainBundle] infoDictionary];

NSString *version = [bundleDic objectForKey:@”CFBundleVersion”];

其中,CFBundleVersion为plist文件的key。

plist文件的所有键值如下:

CFBundleDevelopmentRegion,

DTPlatformName,

CFBundleVersion,

LSRequiresIPhoneOS,

CFBundleSignature,

CFBundleIdentifier,

CFBundleExecutable,

CFBundleDisplayName,

CFBundleShortVersionString,

CFBundleName,

CFBundleSupportedPlatforms,

CFBundlePackageType,

NSBundleResolvedPath,

CFBundleInfoDictionaryVersion,

UIRequiredDeviceCapabilities,

UISupportedInterfaceOrientations,

NSBundleInitialPath,

CFBundleInfoPlistURL,

CFBundleExecutablePath,

DTSDKName,

UIDeviceFamily
在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工程的实际名称。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值