Inref to the above comment, here is the code snippet i use to get the latest version of App from the stores. It is the same technique used in the nugget package you are using. Try to get into the GitHub of the nugget you using, its similar.
public async Task<string> GetLatestVersionAvailableOnStores()
{
string remoteVersion = "";
string bundleID = YOUR_BUNDLE_ID;
bool IsAndroid = DeviceInfo.Current.Platform == DevicePlatform.Android;
var url = IsAndroid ?
"https://play.google.com/store/apps/details?id=" + bundleID :
"http://itunes.apple.com/lookup?bundleId=" + bundleID;
using (HttpClient httpClient = new HttpClient())
{
string raw = await httpClient.GetStringAsync(new Uri(url));
if (IsAndroid)
{
var versionMatch = Regex.Match(raw, @"\[\[""\d+.\d+.\d+""\]\]"); //look for pattern [["X.Y.Z"]]
if (versionMatch.Groups.Count == 1)
{
var versionMatchGroup = versionMatch.Groups[0];
if (versionMatchGroup.Success)
remoteVersion = versionMatch.Value.Replace("[", "").Replace("]", "").Replace("\"", "");
}
}
else
{
JObject obj = JObject.Parse(raw);
if (obj != null)
remoteVersion = obj["results"]?[0]?["version"]?.ToString() ?? "9.9.9";
}
}
return remoteVersion;
}
You can have the Application version by using any static variable in your project. And then you can perform the comparison between both the strings. I used natural comparison to check which is the latest version.
iOS:
SharedProjectClass.ApplicationVersion = NSBundle.MainBundle.InfoDictionary["CFBundlePublicVersionString"].ToString();
Android:
SharedPRojectClass.ApplicationVersion = PackageManager.GetPackageInfo(PackageName, 0).VersionName;
Common Project:
public static class SharedProjectCLass
{
/// <summary>
/// The application version.
/// </summary>
public static string ApplicationVersion;
}
async Task CheckVersion()
{
var currentVersion = SharedProjectClass.ApplicationBuildNumber;
var remoteVersion = await GetLatestVersionAvailableOnStores();
// Function to natural compare the App version of format d.d.d
Func<string, string, bool> CompareNaturalStringsOfAppVersion = (currentVersion, remoteVersion) =>
{
string[] components1 = currentVersion.Split('.');
string[] components2 = remoteVersion.Split('.');
for (int i = 0; i < components1.Length; i++)
{
int value1 = Convert.ToInt32(components1[i]);
int value2 = Convert.ToInt32(components2[i]);
if (value1 < value2)
{
return true; // string1 is lower
}
else if (value1 > value2)
{
return false; // string2 is lower
}
}
return false; // both strings are equal
};
bool needToUpdateApp = CompareNaturalStringsOfAppVersion(currentVersion, remoteVersion);
if (needToUpdateApp)
{
//Show aleart pop-up to user saying new version is available.
}
}