Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public string AppVersion
- {
- get
- {
- var appVersionString = NSBundle.MainBundle.ObjectForInfoDictionary("CFBundleShortVersionString").ToString();
- var appBuildNumber = NSBundle.MainBundle.ObjectForInfoDictionary("CFBundleVersion").ToString();
- return $"v{appVersionString} b{appBuildNumber}";
- }
- }
- using System;
- using System.Linq;
- using Android.Support.Design;
- [assembly: Xamarin.Forms.Dependency(typeof(AppVersionProvider))]
- namespace Shared.Services
- {
- public class AppVersionProvider:IAppVersionProvider
- {
- public Version GetAppVersion()
- {
- var numbers = GetVersionString().Split(new[] {'.'}, 4).Select(s =>
- {
- int value;
- int.TryParse(s, out value);
- return value;
- }).ToArray();
- int major = numbers.ElementAtOrDefault(0);
- int minor = numbers.ElementAtOrDefault(1);
- int revision = numbers.ElementAtOrDefault(2);
- int build = numbers.ElementAtOrDefault(3);
- return new Version(major, minor, build, revision);
- }
- private string GetVersionString()
- {
- #if __ANDROID__
- return BuildConfig.VersionName;
- #endif
- #if __IOS__
- //use the above logic to get the version string;
- #endif
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement