Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Output current app's build version as a string - Xamarin.iOS

I want to output the app's current build version as a string onto my app's about view.

Is there a method of reading this dynamically from the info.plist file or elsewhere rather than hardcoding it in?

E.g: Build Version: 1.0

like image 875
Dave Haigh Avatar asked Oct 31 '13 11:10

Dave Haigh


2 Answers

You can use this code to pull it out of the plist:

NSBundle.MainBundle.InfoDictionary [new NSString ("CFBundleVersion")].ToString ();

You can also use CFBundleShortVersionString, which is the other value for versions. Xamarin recently added support for both in Xamarin Studio.

like image 109
jonathanpeppers Avatar answered Oct 17 '22 01:10

jonathanpeppers


public string AppVersion
{
    get
    {
         var appVersionString = NSBundle.MainBundle.ObjectForInfoDictionary("CFBundleShortVersionString").ToString();
         var appBuildNumber = NSBundle.MainBundle.ObjectForInfoDictionary("CFBundleVersion").ToString();

         return $"v{appVersionString} b{appBuildNumber}";
    }
}
like image 33
richdcs Avatar answered Oct 17 '22 02:10

richdcs