Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alert user #2

Open
mtamony opened this issue Mar 6, 2013 · 10 comments
Open

Alert user #2

mtamony opened this issue Mar 6, 2013 · 10 comments

Comments

@mtamony
Copy link

mtamony commented Mar 6, 2013

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
Copy link
Owner

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
Copy link
Owner

Are you interested in the code that does such check?

@mtamony
Copy link
Author

mtamony commented Mar 6, 2013

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//issues/2#issuecomment-14527256
.

@gcatalfamo
Copy link
Owner

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
Copy link
Author

mtamony commented Mar 6, 2013

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//issues/2#issuecomment-14528075
.

@mtamony
Copy link
Author

mtamony commented Mar 7, 2013

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

@gcatalfamo
Copy link
Owner

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
Copy link
Author

mtamony commented Mar 7, 2013

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
Copy link
Author

mtamony commented Mar 8, 2013

Actually market://details?id=<package_name> 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 mtamony closed this as completed Mar 8, 2013
@mtamony mtamony reopened this Mar 8, 2013
@mtamony
Copy link
Author

mtamony commented Mar 8, 2013

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants