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

问题描述 投票:1回答:1

目前,我有一个自定义用户定义的构建设置,我在其中设置了DISPLAY_NAME。

然后,在Build Settings的General选项卡中,在display name列中,我从用户定义的构建设置中获取此值为$(DISPLAY_NAME)。

我想改为阅读显示名称并从我的Info.plist文件中设置常规构建设置。我怎样才能做到这一点?

ios plist
1个回答
0
投票

您可以使用以下代码。

阅读info.plist文件。

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

infoDictionary:一个字典,由bundle的Info.plist文件构成,包含有关接收者的信息。

阅读自定义.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];
© www.soinside.com 2019 - 2024. All rights reserved.