如何使用Xamarin表单从Play Store获取版本的应用程序数量

发布于 2025-02-01 17:40:56 字数 1045 浏览 3 评论 0原文

我需要检查已安装的应用程序和Playstore应用程序版本的当前版本。如果不是同一应用,则应导航到PlayStore。 我使用xam.plugin.latestversion(2.1.0)从Play Console获取最新的应用程序数量。不幸的是,没有从Play Store获得最新版本的应用程序。以下代码IM使用。

 private async void ChekAppVersion()
      {
          try
          {
               latestVersionNumber = await CrossLatestVersion.Current.GetLatestVersionNumber();
               installedVersionNumber = CrossLatestVersion.Current.InstalledVersionNumber;
              if (installedVersionNumber != latestVersionNumber)
              {
                  await DisplayAlert("New Version", "There is a new version of this app available. Please update now?", "Ok");
                  await CrossLatestVersion.Current.OpenAppInStore();
                  ChekAppVersion();
                                 
              }
              else
              {
                  
              }
          }
          catch (Exception ex)
          {

          }
      }

即时通讯,我获得了installedversionnumber,但我无法获得最新的verseversionnumber(PlayStore)。 请为此提供帮助。

I need to check current version of Installed Application and Playstore application version. If it is not same app should navigate to Playstore .
im using xam.Plugin.LatestVersion(2.1.0) To get the latestversion number of application from play console. unfortunately not getting latest version number of application from play store. The below code im using.

 private async void ChekAppVersion()
      {
          try
          {
               latestVersionNumber = await CrossLatestVersion.Current.GetLatestVersionNumber();
               installedVersionNumber = CrossLatestVersion.Current.InstalledVersionNumber;
              if (installedVersionNumber != latestVersionNumber)
              {
                  await DisplayAlert("New Version", "There is a new version of this app available. Please update now?", "Ok");
                  await CrossLatestVersion.Current.OpenAppInStore();
                  ChekAppVersion();
                                 
              }
              else
              {
                  
              }
          }
          catch (Exception ex)
          {

          }
      }

Im getting the installedVersionNumber, but im unable to get the latestVersionNumber(Playstore).
Please help on this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

画中仙 2025-02-08 17:40:56

他们已从div中删除了该版本,现在已使用JS显示,但是数据仍在< script>标签中。我当前的固定代码是:

    private bool _lockCheckUpdates;

    public async Task<bool> CheckNeedUpdate()
    {
        if (Connectivity.NetworkAccess != NetworkAccess.Internet || _lockCheckUpdates)
            return false;

        _lockCheckUpdates = true;

        try
        {
            HttpClient myClient = CreateClient();

            if (Device.RuntimePlatform == Device.Android)
            {
                var bundle = "com.todo.app"; //ANDROID BUNDLE NAME HERE
                string url = $"https://play.google.com/store/apps/details?id={bundle}&hl=en";
                string raw = await myClient.GetStringAsync(new Uri(url));

                var doc = new HtmlDocument();

                doc.LoadHtml(raw);

                var scripts = doc.DocumentNode.Descendants()
                    .Where(n => n.Name == "script" && n.InnerText.Contains("AF_initDataCallback({key: 'ds:4'"))
                    .ToArray();

                var script = scripts.First().InnerText;

                var engine = new Jurassic.ScriptEngine();
                var eval = "(function() { var AF_initDataCallback = function(p) { return p.data[1][2][140][0][0][0]; };  return " + script + " })()";
                var result = engine.Evaluate(eval);
                //var json = JSONObject.Stringify(engine, result); //for debug, check in browser console with JSON.parse(json) 

                var remote = $"{result}".ToDouble();
                var local = App.Version.ToDouble();
                return local < remote;

            }
            else if (Device.RuntimePlatform == Device.iOS)
            {
                var bundle = "com.todo.app";//iOS BUNDLE NAME HERE
                string url = $"http://itunes.apple.com/lookup?bundleId={bundle}";
                string raw = await myClient.GetStringAsync(new Uri(url));

                var dto = JsonConvert.DeserializeObject<AppStoreRecord>(raw);
                double local = App.Version.ToDouble();
                if (dto.ResultCount > 0)
                {
                    double remote = dto.Results[0].Version.ToDouble();
                    return remote > local;
                }
            }
        }
        catch (Exception e)
        {
            Logger.Error("CheckNeedUpdate", e);
        }
        finally
        {
            _lockCheckUpdates = false;
        }

        return false;

    }

使用nugets

侏罗纪评估页面上的脚本,
htmlagilitypack解析html,
Xamarin.sentials检查我们是否在线,
appomobi.specials for .todouble()等,

我希望这对修复

They have removed the version from div, now it's displayed with js, but data is still there inside a <script> tag. My current fixed code is:

    private bool _lockCheckUpdates;

    public async Task<bool> CheckNeedUpdate()
    {
        if (Connectivity.NetworkAccess != NetworkAccess.Internet || _lockCheckUpdates)
            return false;

        _lockCheckUpdates = true;

        try
        {
            HttpClient myClient = CreateClient();

            if (Device.RuntimePlatform == Device.Android)
            {
                var bundle = "com.todo.app"; //ANDROID BUNDLE NAME HERE
                string url = 
quot;https://play.google.com/store/apps/details?id={bundle}&hl=en";
                string raw = await myClient.GetStringAsync(new Uri(url));

                var doc = new HtmlDocument();

                doc.LoadHtml(raw);

                var scripts = doc.DocumentNode.Descendants()
                    .Where(n => n.Name == "script" && n.InnerText.Contains("AF_initDataCallback({key: 'ds:4'"))
                    .ToArray();

                var script = scripts.First().InnerText;

                var engine = new Jurassic.ScriptEngine();
                var eval = "(function() { var AF_initDataCallback = function(p) { return p.data[1][2][140][0][0][0]; };  return " + script + " })()";
                var result = engine.Evaluate(eval);
                //var json = JSONObject.Stringify(engine, result); //for debug, check in browser console with JSON.parse(json) 

                var remote = 
quot;{result}".ToDouble();
                var local = App.Version.ToDouble();
                return local < remote;

            }
            else if (Device.RuntimePlatform == Device.iOS)
            {
                var bundle = "com.todo.app";//iOS BUNDLE NAME HERE
                string url = 
quot;http://itunes.apple.com/lookup?bundleId={bundle}";
                string raw = await myClient.GetStringAsync(new Uri(url));

                var dto = JsonConvert.DeserializeObject<AppStoreRecord>(raw);
                double local = App.Version.ToDouble();
                if (dto.ResultCount > 0)
                {
                    double remote = dto.Results[0].Version.ToDouble();
                    return remote > local;
                }
            }
        }
        catch (Exception e)
        {
            Logger.Error("CheckNeedUpdate", e);
        }
        finally
        {
            _lockCheckUpdates = false;
        }

        return false;

    }

Using nugets

Jurassic to evaluate the script on page,
HtmlAgilityPack to parse html,
Xamarin.Essentials to check if we are online,
and AppoMobi.Specials for .ToDouble() etc

I hope this could also be useful to fix https://github.com/edsnider/latestversionplugin/issues/43 :)

橘虞初梦 2025-02-08 17:40:56

您使用的插件不再适用于Android https://githbithub.com/github.com/github.com/edsnider/latestversionplugin/问题/43

您需要找到一种获取所需信息的新方法。

The plugin you are using no longer works for Android https://github.com/edsnider/latestversionplugin/issues/43

You will need to find a new way to get the desired information.

蘑菇王子 2025-02-08 17:40:56

PR已在此插件上进行...它再次工作;-)

PR has been made on this plugin... it works again ;-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文