繁体   English   中英

如何获取 Playstore 应用程序版本名称和版本代码 android 应用程序 cordova

[英]How to get playstore app verson name and version code android application cordova

我在 Play 商店中有一个应用程序,如何使用 Cordova 获取 Play 商店应用程序版本名称和版本代码,任何建议表示赞赏

要检查更新,您需要采用特定于平台的方法

iOS 方法

  1. 您需要向https://itunes.apple.com/lookup?bundleId=BUNDLE_ID发送请求
  2. 获得结果后,您可以从response.data.results[0].version获取version ,然后将其与本地版本进行比较。
  3. 现在,如果版本不同,您可以使用链接https://itunes.apple.com/app/APP_ID将用户发送到应用商店

Android 方法

  1. 您需要向https://play.google.com/store/apps/details?id=BUNDLE_ID发送请求
  2. 获得结果后,您可以使用下面的代码片段提取版本。
  3. 现在,如果版本不同,您可以使用链接https://play.google.com/store/apps/details?id=BUNDLE_ID将用户发送到应用商店

片段

var parser = new DOMParser(),
  doc = parser.parseFromString(response.data, 'text/html');
if (doc) {
  var tag = doc.querySelectorAll(".hAyfc .htlgb");
  if (tag && tag[6]) {
    let storeVersion = tag[6].innerText.trim();
    if (local_version != storeVersion) {
      // send to stroe
    }
  }
}

Android 方法是一种基于 DOM 的解决方法,因为我们直接使用tag[6].innerText.trim()访问索引,但对于 iOS,它是一个可靠的方法。

这是获取 Play 商店应用程序版本号的代码,以及如何实现强制更新选项。 我已经对其进行了测试,并且运行良好。

  var your_url =YOUR_PLAY STORE APP_URL;
          $.ajax({
            url: your_url,
            type: 'GET',
            success: function(res) {
                let storeVersion =null;
                var doc=null;
                var tag=null;
               var parser = new DOMParser(),
               doc = parser.parseFromString(res, 'text/html');
               if (doc) {
                tag = doc.querySelectorAll(".hAyfc .htlgb");
               if (tag && tag[6]) {
               storeVersion = tag[6].innerText.trim();

               }
               }
               cordova.getAppVersion.getVersionNumber(function(versionNumber){
                var curentVersion = versionNumber;
                var playStoreVersion = tag[6].innerText.trim();
                //alert("loacal version = "+curentVersion+"    "+"playstore version = "+playStoreVersion);
                if(curentVersion<playStoreVersion){
                    navigator.notification.confirm("There is New Version of this application available,Click Upgrade to Update now ?", onConfirm, "Confirmation", "Update,Later");
                }else{
                }
            });
            }
        }); 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM