Reputation: 2405
i have one app in the play store, how can get play store application version name and version code using Cordova, any suggestion appreciated
Upvotes: 0
Views: 1832
Reputation: 2405
Here is the code to get the version number of the Play store application, as well as how to implement a force update option. I've tested it, and it is working perfectly.
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{
}
});
}
});
Upvotes: 0
Reputation: 10237
To check updates, you need to take a platform-specific approach
iOS Approach
https://itunes.apple.com/lookup?bundleId=BUNDLE_ID
version
from response.data.results[0].version
and then compare it with the local version.https://itunes.apple.com/app/APP_ID
Android Approach
https://play.google.com/store/apps/details?id=BUNDLE_ID
https://play.google.com/store/apps/details?id=BUNDLE_ID
snippet
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 approach is rather a DOM-based workaround as we are accessing the index directly using
tag[6].innerText.trim()
, but for iOS, it's a solid one.
Upvotes: 1