Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

check appstore app version xmarin (Force upgrading the app)

Tags:

xamarin.ios

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?

like image 270
Nilay Patel Avatar asked Nov 07 '25 10:11

Nilay Patel


1 Answers

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;
        }
like image 63
Nilay Patel Avatar answered Nov 11 '25 11:11

Nilay Patel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!