Open mtamony opened 11 years ago
I am finally able to find the version number and my javascript file uses it to check if the version is actually the latest. If not, it prompts an update. (this is what my apps do, the plugin just digs the version name and version code) I basically made my app query a webservice I did for myself, but you could do anything.
Something like is v_code on the phone the same of the v_code the server is showing? Yes: do nothing No: notification.confirmation(text, onConfirm, "button1,button2") on which is written something like: You should update! Do it now? YES / MAYBE LATER
Yes, I already added it to the phonegap plugin list :) (https://github.com/phonegap/phonegap-plugins/tree/master/Android)
Are you interested in the code that does such check?
Sure that would be helpful. I am trying to learn about parsing xml. I built an app and got it in app stores but I'm really new at all this.
On Wed, Mar 6, 2013 at 1:29 PM, gcatalfamo notifications@github.com wrote:
Are you interested in the code that does such check?
— Reply to this email directly or view it on GitHubhttps://github.com/gcatalfamo/Version/issues/2#issuecomment-14527256 .
Ok, listen up: create an xml file somewhere (server, dropbox public anywhere), with this content:
<version>
<v_code>1</v_code>
<v_name>1.0</v_name>
<v_url>https://play.google.com/store/apps/details?id=your.package.name</v_url>
</version>
And now, this is the function I use inside my app:
function checkVersion() {
$.ajax({ type: "GET", url: "url of my xml file", dataType: "xml",
success: function(xml) {
$(xml).find('version').each(function(){
var vcode = $(this).find('v_code').text(); //get the v_code in the xml file
window.plugins.version.getVersionCode(
function(version_code) {
if(version_code != vcode){
navigator.notification.confirm(
'A new version is out! Get it now!', // message
onVersion, // callback to invoke with index of button pressed
'Update available', // title
'Update now!, Maybe later' // buttonLabels
);
}
},
function(errorMessage) {
console.log(errorMessage);
}
);
});
}
});
}
//This function describes the button behavior. In this case, it opens the app page on the play store. function onVersion(button) { if(button == 1){ window.open('market://details?id=your.package.name'); } }
Please let me know if this helped you.
Thank you so much!! I will try this and see how it goes.
On Wed, Mar 6, 2013 at 1:44 PM, gcatalfamo notifications@github.com wrote:
Ok, listen up: create an xml file somewhere (server, dropbox public anywhere), with this content:
1 1.0 https://play.google.com/store/apps/details?id=your.package.name
And now, this is the function I use inside my app:
function checkVersion() { $.ajax({ type: "GET", url: "url of my xml file", dataType: "xml", success: function(xml) { $(xml).find('version').each(function(){ var vcode = $(this).find('v_code').text(); //get the v_code in the xml file
window.plugins.version.getVersionCode( function(version_code) { if(version_code != vcode){ navigator.notification.confirm( 'A new version is out! Get it now!', // message onVersion, // callback to invoke with index of button pressed 'Update available', // title 'Update now!, Maybe later' // buttonLabels ); } }, function(errorMessage) { console.log(errorMessage); } ); }); }
});
}
//This function describes the button behavior. In this case, it opens the app page on the play store. function onVersion(button) { if(button == 1){ window.open('market://details?id=your.package.name'); } }
Please let me know if this helped you.
— Reply to this email directly or view it on GitHubhttps://github.com/gcatalfamo/Version/issues/2#issuecomment-14528075 .
It Worked!! Thank you. One final question. How are you triggering it? Are you using $(document).ready?
No, but you could.
I personally use this:
<script type="text/javascript" charset="utf-8">
document.addEventListener("deviceready", onDeviceReady, true);
</script>
function onDeviceReady() {
//other starting functions
checkVersion(); // <= HERE;
}
Yes I put it there too. Now I'm off to try and get this working for the iOS version. Thanks again for your help.
Actually market://details?id=
If anyone comes across this and needs a solution for iOS search for Harpy on GitHub. Works perfectly.
This is an issue with Cordova's new InAppBrowser. It seems to prepend the http://
Opening of market:// with window.open will be resolved in Cordova 2.6
What are you doing once you have the version number? I am able to get the number in log but I'm not sure how to alert user of a newer version.
Thank you for the plugin too. Have you thought of adding it to the phonegap plugins list?