Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. public string AppVersion
  2. {
  3. get
  4. {
  5. var appVersionString = NSBundle.MainBundle.ObjectForInfoDictionary("CFBundleShortVersionString").ToString();
  6. var appBuildNumber = NSBundle.MainBundle.ObjectForInfoDictionary("CFBundleVersion").ToString();
  7.  
  8. return $"v{appVersionString} b{appBuildNumber}";
  9. }
  10. }
  11.  
  12. using System;
  13. using System.Linq;
  14. using Android.Support.Design;
  15. [assembly: Xamarin.Forms.Dependency(typeof(AppVersionProvider))]
  16. namespace Shared.Services
  17. {
  18. public class AppVersionProvider:IAppVersionProvider
  19. {
  20. public Version GetAppVersion()
  21. {
  22. var numbers = GetVersionString().Split(new[] {'.'}, 4).Select(s =>
  23. {
  24. int value;
  25. int.TryParse(s, out value);
  26. return value;
  27. }).ToArray();
  28. int major = numbers.ElementAtOrDefault(0);
  29. int minor = numbers.ElementAtOrDefault(1);
  30. int revision = numbers.ElementAtOrDefault(2);
  31. int build = numbers.ElementAtOrDefault(3);
  32. return new Version(major, minor, build, revision);
  33.  
  34. }
  35.  
  36. private string GetVersionString()
  37. {
  38. #if __ANDROID__
  39. return BuildConfig.VersionName;
  40. #endif
  41. #if __IOS__
  42. //use the above logic to get the version string;
  43. #endif
  44. }
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement