用来描述bundles,告诉你如何解析bundles的内容
During the copy operation, Xcode uses build settings to perform variable substitution. It also inserts additional keys representing configuration that you specify in other ways. For example, you indicate the deployment target for an iOS app in Xcode’s project editor. Xcode translates that into the MinimumOSVersion key that it adds during the copy. As a result of these changes, the information property list file that ships with your app isn’t identical to the source file in your project.
plist操作
获取plist内容的方法
通过绝对路径查找(适合查找不在当前工程bundle中的plist)
// 本地沙盒路径列表
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
//NSSearchPathForDirectoriesInDomains
//第一个参数表示要获取的目录类型(NSDocumentDirectory、NSLibraryDirectory、NSCachesDirectory)
//第二个参数表示要搜索的目录域,(NSUserDomainMask、NSLocalDomainMask、NSNetworkDomainMask)
//第三个参数表示是否要将~扩展为当前用户的主目录。默认为YES。
// 获取沙河路径
NSLog(@"paths:%@",paths);
NSString* plistPath = [paths objectAtIndex:0];
NSLog(@"plistPath:%@",plistPath);//fileName:/Users/xxx/Library/Containers/test.OCTest/Data/Documents
// 拼接完整路径
NSString* fileName = [plistPath stringByAppendingPathComponent:@"test.plist"];
NSLog(@"fileName:%@",fileName);//fileName:/Users/xxx/Library/Containers/test.OCTest/Data/Documents/test.plist
NSDictionary* fileContent = [NSDictionary dictionaryWithContentsOfFile:fileName];
直接从bundle中找相关plist
NSBundle *bundle = [NSBundle bundleForClass:xxx.class];
NSString *plistPath = [bundle pathForResource:@"test" ofType:@"plist"];//在bundle中找test.plist的文件
NSDictionary *dicPlist = [NSDictionary dictionaryWithContentsOfFile:plistPath];
if (!dicPlist.count) {
return YES;
}
BOOL res = [[dicPlist objectForKey:@"name"] boolValue];//找名叫name的属性数据
return res;
plist默认填充的信息都是什么意思
在xcode的build settings中添加info.plist file后如何使用

BOOL isDebugMode = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"debugMode"];
//objectForInfoDictionaryKey用于获取应用程序的信息字典(Info.plist)中指定键名的键值。
NSString* name = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"name"];
NSLog(@"isDebugMode: %d", isDebugMode);
NSLog(@"name: %@", name);
NSString *appName = [[[NSBundle mainBundle] infoDictionary] objectForKey:(id)kCFBundleNameKey];
名字
如果plist中叫icon file 则xcode代码中就叫 CFBundleIconFile
Xcode在复制操作时使用构建设置进行变量替换,并插入额外的配置键。例如,您在项目编辑器中指定的iOS应用部署目标会被转换为MinimumOSVersion键。可以通过绝对路径或从bundle中获取plist内容,使用NSBundle和dictionaryWithContentsOfFile方法。Info.plist文件中的键值可以使用objectForInfoDictionaryKey方法访问,如debugMode和应用名称。

4440

被折叠的 条评论
为什么被折叠?



