Joh*_*ith 87 iphone xcode cocoa-touch objective-c info.plist
我想从Info.plist中读取捆绑版本信息到我的代码中,最好是作为字符串.我怎样才能做到这一点?
gca*_*amp 199
您可以将Info.plist作为字典阅读
[[NSBundle mainBundle] infoDictionary]
Run Code Online (Sandbox Code Playgroud)
而且您可以通过CFBundleVersion
这种方式轻松获得密钥版本.
最后,你可以获得版本
NSDictionary* infoDict = [[NSBundle mainBundle] infoDictionary];
NSString* version = [infoDict objectForKey:@"CFBundleVersion"];
Run Code Online (Sandbox Code Playgroud)
aya*_*aya 10
对于Swift用户:
if let version = NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleShortVersionString") {
print("version is : \(version)")
}
Run Code Online (Sandbox Code Playgroud)
对于Swift3用户:
if let version = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") {
print("version is : \(version)")
}
Run Code Online (Sandbox Code Playgroud)
我知道自寻求和回答以来已经过去了一段时间。
从iOS8开始,接受的答案可能无效。
这是现在的新方法:
NSString *version = (__bridge id)CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), kCFBundleVersionKey);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
39682 次 |
最近记录: |