Getting App build number in Phonegap

Posted By : Avilash Choudhary | 25-Mar-2015

app build number phonegap

While developing a project in Phonegap you might need the application build number. Like you might need to delete some storage from previous application that already installed on the device. You can store the application build number in the local storage and next time when you get the another build of that application then you can match the two build numbers and do the activity that you want.

 

This is basically needed when the application is in development mode. In development mode, if your application old build is installed on the device, and without removing  that build you install the new build, So in that case, your local storage and your local database might create problems. So the best way, when installing new build of application you can clean the previous storage and database while installing new build. but you need to change the build number every time you send the build to the users. if the previous build number is different from the current build number then clean the storage.

You need to install the plugin using command line:

cordova plugin add https://github.com/danmichaelo/cordova-plugin-appinfo.git

After installing the plugin you can just put the below code, this small peace of code will give you the app build number.

While sending the build. i.e. if you are developing application for iOS then in xCode you can change the build number. 

navigator.appInfo.getVersion(function(ver) {
                             
              
            var oldVersion =  window.localStorage.getItem("key");
            if (ver != oldVersion) {
                  
			// do some activity here
                         window.localStorage.setItem("key", ver);
            }
        });

This plugin provides support on different platforms such as Android,iOS and Windows Phone 8.  

 

THANKS

About Author

Author Image
Avilash Choudhary

Avilash has excellent experience in developing mobile and web applications using jQuery , Javascript and PhoneGap. His hobbies are watching and playing cricket.

Request for Proposal

Name is required

Comment is required

Sending message..