简体   繁体   English

如何在构建设置中从Info.plist读取值?

[英]How can you read values from Info.plist in build settings?

Currently, I have a custom user defined build settings in which I set the DISPLAY_NAME. 目前,我有一个自定义的用户定义的构建设置,其中设置了DISPLAY_NAME。

Then, in the General tab of Build Settings, in the display name column, I fetch this value as $(DISPLAY_NAME) from my user defined build settings. 然后,在“构建设置”的“常规”选项卡的“显示名称”列中,从用户定义的构建设置中将此值提取为$(DISPLAY_NAME)。

I want to instead read the Display Name and set the general build settings from my Info.plist file. 我想改为读取显示名称,然后从我的Info.plist文件中设置常规构建设置。 How can I do this? 我怎样才能做到这一点?

you can use the following code. 您可以使用以下代码。

Read info.plist file. 读取info.plist文件。

NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
NSString *value = [infoDict objectForKey:@"keyName"];

infoDictionary: A dictionary, constructed from the bundle's Info.plist file, that contains information about the receiver. infoDictionary:从捆绑软件的Info.plist文件构造的字典,其中包含有关接收者的信息。

Read a custom .plist file 读取自定义.plist文件

   NSString *file = [[NSBundle bundleForClass:[self class]] pathForResource:"nameOfPlist" ofType:@"plist"];

    if (!file) {
        NSLog(@"Please add a plist config file to your project.");
        return nil;
    }

    NSDictionary *plistDict =  [NSDictionary dictionaryWithContentsOfFile:file];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Info.plist中读取自定义键的值并在Xcode的构建设置中使用它? - How can I read a custom key's value in Info.plist and use it in Xcode's build settings? 如何在info.plist中读取环境变量? - How to read environment variables in info.plist? NEHotspotHelper的info.plist设置 - info.plist settings of NEHotspotHelper 使用 CocoaPods 安装的框架的构建设置中的空 Info.plist 路径 - Empty Info.plist paths in build settings with frameworks installed with CocoaPods Xcode:从“构建设置”中误删除了info.plist和prefix.pch - Xcode: Accidentally deleted info.plist and prefix.pch from 'build settings' 如何像在info.plist中一样在Settings.bundle中访问该应用程序的版本? - How can I access version of the app within Settings.bundle like it is in info.plist? 你可以在 iPhone App Info.plist 中以编程方式修改 NSExceptionMinimumTLSVersion 吗? - Can you modify NSExceptionMinimumTLSVersion in the iPhone App Info.plist programmatically? 无法在XCODE 7中编辑Info.plist(具有读/写权限) - Can't edit Info.plist (read/write permission) in XCODE 7 使用构建阶段中的文件预处理Info.plist - Preprocess Info.plist with file from Build Phase 如何在构建时将按目标UIAppFonts添加到共享的Info.plist文件中 - How can I add per-target UIAppFonts to a shared Info.plist file at build time
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM