Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get your own app version from xcode?

I wonder if there is a way to get your own app version in code after you put it in the "Summary" tab in xCode. One way seems to be to search Info.plist for CFBundleVersion key, but is there any other, easier, more convenient way?

like image 918
Rad'Val Avatar asked Oct 31 '11 18:10

Rad'Val


People also ask

How do I find out app version?

Open the Settings app on your Android device. Open the "Applications" and/or "Application Manager" section. Tap on your app to select it. The App Settings Panel has multiple options including App Version, Notifications, and Location.


3 Answers

You can find it in the main bundle. I think it's something like:

[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
like image 85
Chris Ledet Avatar answered Oct 14 '22 01:10

Chris Ledet


I typically use the Build number (CFBundleVersion) to keep track of, well, the number of builds, and the Version number (CFBundleShortVersionString) for marketing purposes. I use a run script to auto-increment my build number and I update the version number manually before each new release. So if you want to include the actual Version number in your code as opposed to the Build number, use this:

[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]

or

[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];

Here's the run script that increments the build number for anyone interested:

#!/bin/bash

buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${PROJECT_DIR}/${INFOPLIST_FILE}")
buildNumber=$(($buildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "${PROJECT_DIR}/${INFOPLIST_FILE}"
like image 28
lobianco Avatar answered Oct 13 '22 23:10

lobianco


For Swift:

Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString")
like image 15
bjd23 Avatar answered Oct 14 '22 01:10

bjd23