我正在开发一个通用应用程序,并且想在我的代码中访问存储在 app-info.plist 文件中的值。
原因:我使用以下方法从 Storyboard 动态实例化 UIViewController:
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
self = [storyboard instantiateViewControllerWithIdentifier:@"ExampleViewController"];
现在,上面的 Storyboard名称@“MainStoryboard_iPhone”很丑。
我想做这样的事情:
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:appInfo.mainStoryboardBaseNamePhone bundle:nil];
self = [storyboard instantiateViewControllerWithIdentifier:@"ExampleViewController"];
其中 appInfo 可能是 app-info.plist 中所有值的 NSDictionary
最佳答案
您项目的 info.plist 中的属性可以通过以下方式直接访问...
[[NSBundle mainBundle] objectForInfoDictionaryKey:key_name];
例如,要获取版本号,您可以执行以下操作
NSString *appVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];
有一个问题是版本号现在在 info.plist 中有两个属性 - 但你明白了吗?如果您将 info.plist 视为源代码(右键单击 info.plist - 选择 Open As),那么您将看到您可以使用的所有各种键名。
关于iphone - iOS:在代码中访问 app-info.plist 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9530075/