现在的位置: 首页 > 综合 > 正文

cocos2d-x 解析 Info.plist 及其它.plist

2018年05月27日 ⁄ 综合 ⁄ 共 783字 ⁄ 字号 评论关闭

首先说明一点在iPhone开发时, 读取Info.plist是有特定做法的

即类似"

[[NSBundlemainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey]

"的做法. 

但cocos2d-x为是多平台移植, 不能用NS....这里东西. 所以plist文件的解析, 需要自己写.

比如:

    const char* l_path = CCFileUtils::fullPathFromRelativePath("XXX.plist");

    CCMutableDictionary<string, CCObject*>* l_dic = CCFileUtils::dictionaryWithContentsOfFile(l_path);

    string l_key = string("keyValue.....");

    CCString* l_result = (CCString*)l_dic->objectForKey(l_key);

//如果转成string的话

    string l_stringResult = l_result->toStdString();

 

但在解析Info.plist的时候, 最到一个问题. 在XCode打开看到键为"Bundle version", 带进去一试. 返回的CCString为空. 开始我以为是键值里面不能有空格, 但我在Info.plist自己加了个键值对, 也带空格. 可以得到它的Value.

最后用其它编辑器(我用的是jEdit)打到Info.plist才找到原因:

"Bundle version"的真正键为"CFBundleVersion", 是XCode为了保护关键信息, 在显示上做了特殊的处理. 把CFBundleVersion代进去, 就OK了.

本篇为原创,  转载请注明!

抱歉!评论已关闭.