gcatalfamo / Version

Phonegap Plugin that creates methods to expose the version name and version code of an Android app
6 stars 12 forks source link

Alert user #2

Open mtamony opened 11 years ago

mtamony commented 11 years ago

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?

gcatalfamo commented 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)

gcatalfamo commented 11 years ago

Are you interested in the code that does such check?

mtamony commented 11 years ago

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 .

gcatalfamo commented 11 years ago

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.

mtamony commented 11 years ago

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 .

mtamony commented 11 years ago

It Worked!! Thank you. One final question. How are you triggering it? Are you using $(document).ready?

gcatalfamo commented 11 years ago

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;
}
mtamony commented 11 years ago

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.

mtamony commented 11 years ago

Actually market://details?id= is being prepended by http:// when I click download the update.

If anyone comes across this and needs a solution for iOS search for Harpy on GitHub. Works perfectly.

mtamony commented 11 years ago

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