Forum Xamarin.Forms

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Getting Build/Version numbers from Device Specific Projects

MattButlerMattButler USUniversity ✭✭

PCL Based X.Forms applciation. I have a requirement to display the build number on our "About" screen. I've created a dependency service and found code about how to do this on Android, but haven't a clue about how to get to it on iOS.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using MyProject.DeviceInterfaces;
using Android.Content.PM;
using Xamarin.Forms;
using MyProject.Android.DeviceSpecificCode;

[assembly: Dependency(typeof(App_Droid))]

namespace MyProject.Android.DeviceSpecificCode
{
    public class App_Droid : IApp
    {
        public string GetBuildNumber()
        {
            Context context = Forms.Context;
            PackageManager manager = context.PackageManager;
            PackageInfo info = manager.GetPackageInfo(context.PackageName, 0);
            return info.VersionName;
        }
    }
}

Seems to do the trick on Android. How to do the same thing on iOS. Any help?

Posts

  • MattButlerMattButler USUniversity ✭✭

    FYI, they both work after a test ;)

  • RUBENCARREONRUBENCARREON USMember ✭✭

    Thanks for sharing Matt
    Do you know how to do it for WinPhone Silverlight 8.1?

  • RUBENCARREONRUBENCARREON USMember ✭✭

    Never mind, is pretty easy

    public class Version : IVersion { public string GetBuildNumber() { return GetBuildNumber(); } }

  • RUBENCARREONRUBENCARREON USMember ✭✭

    @RUBENCARREON said:
    Never mind, is pretty easy

    public class Version : IVersion { public string GetBuildNumber() { return GetBuildNumber(); } }

    mmm, sorry this code is not working...

  • venkat.0969venkat.0969 USMember ✭✭

    Can some one let me know how to get the version from the windows phone store and also how to recognize the locally installed application in the winphone.

  • venkat.0969venkat.0969 USMember ✭✭
    edited April 2017

    http://www.michielpost.nl/PostDetail_67.aspx
    Solution to get version number from the manifest file (winphone)

    But i am looking for code to know the current version available in the windows phone store...

    Few more links on how to get he store versions from android and IOS.

    https://forums.xamarin.com/discussion/91481/how-to-prompt-the-user-for-new-upgrades-to-the-app

  • GSalunkheGSalunkhe INMember ✭✭

    @MattButler said:
    FYI, they both work after a test ;)

    Hi @MattButler

    Can you please tell how to do it in Xamarin Forms common project, As I am considering showing it on Android and iOS both.

    Thanks
    gsalunkhe

  • DR_nathouDR_nathou BEMember ✭✭

    Thanks @MattButler you saved my ass in 2017 ^^

Sign In or Register to comment.