4

Is there a way in xamarin.ios or xamarin.android or mvvmcross5 to check version number of app in the appstore?

Can someone please redirect me to a sample?

Nilay Patel
  • 146
  • 1
  • 4
  • Possible duplicate of [Check if my app has a new version on AppStore](https://stackoverflow.com/questions/6256748/check-if-my-app-has-a-new-version-on-appstore) – Jason Oct 18 '17 at 18:57
  • 1
    @Jason It is not duplicate because that question/answer is for swift and this for xamarin.ios – Stefanija Apr 13 '18 at 11:28

2 Answers2

3

Here you go. I found a solution for it:

private string GetAppStoreAppVersion()
        {
            string appStoreAppVersion = string.Empty;

            try
            {
                var dictionary = NSBundle.MainBundle.InfoDictionary;
                string applicationID = dictionary[@"CFBundleIdentifier"].ToString();


                NSUrl url = new NSUrl($"http://itunes.apple.com/lookup?bundleId={applicationID}");
                NSData data = NSData.FromUrl(url);
                NSError error = new NSError();
                NSDictionary lookup = NSJsonSerialization.Deserialize(data, 0, out error) as NSDictionary;

                if (error == null
                    && lookup != null
                    && lookup.Keys.Length >= 1
                    && lookup["resultCount"] != null
                    && Convert.ToInt32(lookup["resultCount"].ToString()) > 0)
                {

                    var results = lookup[@"results"] as NSArray;

                    if (results != null && results.Count > 0)
                    {
                        appStoreAppVersion = results.GetItem<NSDictionary>(0)["version"].ToString();

                    }
                }

            }
            catch (Exception ex)
            {
                //No need to throw an exception if version check fails 
            }


            return appStoreAppVersion;
        }
Nilay Patel
  • 146
  • 1
  • 4
  • thank you, this is just the xamarin implementation of what i was looking for. Came here from https://stackoverflow.com/a/47458347/578743 and could not make much use of the swift implementation. – Maverick1st Nov 15 '21 at 11:24
1

If you are looking to implement this in back-end then here is the code to get it.

string url = "http://itunes.apple.com/lookup?bundleId=yourbundleid";

            using (var webClient = new System.Net.WebClient())
            {
                string jsonString = webClient.DownloadString(string.Format(url));

                var lookup = JsonConvert.DeserializeObject<Dictionary<string, object>>(jsonString);


                if (lookup != null
                    && lookup.Count >= 1
                    && lookup["resultCount"] != null
                    && Convert.ToInt32(lookup["resultCount"].ToString()) > 0)
                {

                    var results = JsonConvert.DeserializeObject<List<object>>(lookup[@"results"].ToString());


                    if (results != null && results.Count > 0)
                    {
                        var values = JsonConvert.DeserializeObject<Dictionary<string, object>>(results[0].ToString());
                        appStoreAppVersion = values.ContainsKey("version") ? values["version"].ToString() : string.Empty;

                    }
                }
            }

            return appStoreAppVersion;
Nilay Patel
  • 146
  • 1
  • 4