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

2

13

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

Rowena answered 31/10, 2013 at 11:21 Comment(0)
F
31

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.

Fractious answered 31/10, 2013 at 11:51 Comment(1)
NSBundle.MainBundle.InfoDictionary is really useful to me for grabbing other strings that I need. ThanksRowena
B
4
public string AppVersion
{
    get
    {
         var appVersionString = NSBundle.MainBundle.ObjectForInfoDictionary("CFBundleShortVersionString").ToString();
         var appBuildNumber = NSBundle.MainBundle.ObjectForInfoDictionary("CFBundleVersion").ToString();

         return $"v{appVersionString} b{appBuildNumber}";
    }
}
Bomarc answered 29/11, 2016 at 9:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.