从命令行工具检索info.plist文件 [英] Retrieve info.plist file from command-line tool
问题描述
使用以下步骤,我可以将info.plist嵌入到命令行工具中。
Using the following steps, I'm able to embed an info.plist into a command-line tool.
我知道如何从.bundle中检索 plist
文件,但我不知道如何在单文件工具中像我一样做。
I know how to retrieve the plist
file from a .bundle, but I'm not sure how to do the same in a single-file tool like I've got.
我已经将info.plist嵌入到命令行工具中,以便我可以存储版本。有没有人知道如何在运行时检索它,以便我可以确定运行的版本?
I've embedded the info.plist into the command-line tool so that I can store the version in it. Does anyone know how I can retrieve it at run-time so I can determine what version is running?
感谢
推荐答案
__ info_plist
是一个魔术部分名称,使以下Just Work:
__info_plist
is a "magic" section name that makes the following Just Work:
NSBundle *bundle = [NSBundle mainBundle];
id version = [bundle objectForInfoDictionaryKey: (NSString*) kCFBundleVersionKey];
NSLog(@"mainBundle.version = %@", version);
如果您需要阅读嵌入在不同于当前运行的可执行文件的可执行文件的bundle,这个回答由Bavarious 从评论有一个更全面的方法列表。
If you need to read a bundle embedded in a different executable than the one currently running, this answer by Bavarious from the comments has a more comprehensive list of approaches.
这篇关于从命令行工具检索info.plist文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!