Xcode 使用CbundleGetVersionNumber
我想使用以下方法从info.plist获取版本号:Xcode 使用CbundleGetVersionNumber,xcode,nsbundle,Xcode,Nsbundle,我想使用以下方法从info.plist获取版本号: NSString *version = (NSString *)CFBundleGetVersionNumber(CFBundleGetMainBundle()); 这并没有给我预期的捆绑包版本的字符串值 这确实给了我期望的字符串: NSString *version = (NSString *)CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), kCFBundleVer
NSString *version = (NSString *)CFBundleGetVersionNumber(CFBundleGetMainBundle());
这并没有给我预期的捆绑包版本的字符串值
这确实给了我期望的字符串:
NSString *version = (NSString *)CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), kCFBundleVersionKey);
我想知道如何使用第一个表单,因为它看起来是从info.plist获取版本的首选方法
以下是我如何使用结果:
htmlAbout = [htmlAbout stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"[version]"] withString:version];
我在Xcode 4.1中工作
谢谢您的程序中存在严重的转换错误:
CbundlegetVersionNumber
返回UInt32
,无法通过typecast转换为NSString
(或任何objc类型)。请参阅苹果文档中的CbundlegetVersionNumber:
它说你的第二种形式实际上是X.Y版本的首选方式:
如果使用其他版本号样式,即X、X.Y或X.Y.Z,
您可以将CbundleGetValueForInfoDictionaryKey与键一起使用
KCFBundLeverOnKey,用于将版本号作为字符串从
bundle的信息字典
如果您使用的是ARC
CFStringRef ver = CFBundleGetValueForInfoDictionaryKey(
CFBundleGetMainBundle(),
kCFBundleVersionKey);
NSString *appVersion = (__bridge NSString *)ver;
谢谢然后我对
kcfbundleverionkey
的值很在行。
CFStringRef ver = CFBundleGetValueForInfoDictionaryKey(
CFBundleGetMainBundle(),
kCFBundleVersionKey);
NSString *appVersion = (__bridge NSString *)ver;