我正在写一个iPhone应用程序。它已经发布,但我想添加一个功能,其版本号显示。

我不希望对我发布的每个版本都手动执行此操作……

objective-C中有办法找出我的应用的版本吗?


当前回答

// Syncs with App Store and Xcode Project Settings Input
NSString *appVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];

其他回答

这就是我在申请中所做的

NSString *appVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];

希望这个简单的答案能帮助到一些人……

// Syncs with App Store and Xcode Project Settings Input
NSString *appVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];

您可以在plist.info中指定CFBundleShortVersionString字符串,并使用提供的API以编程方式读取该字符串。

你可以使用infoDictionary从info中获取版本细节。这段代码适用于swift 3。只需调用此方法并在任何首选的UI元素中显示版本。

Swift-3  

func getVersion() -> String {
    let dictionary = Bundle.main.infoDictionary!
    let version = dictionary["CFBundleShortVersionString"] as! String
    let build = dictionary["CFBundleVersion"] as! String
    return "v\(version).\(build)"
}

你可以试试这个方法:

NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];