本文讲解cordova-plugin-app-version插件以及如何在Wex5中使用该插件。

1.插件概述

APP版本信息插件,通过该插件可获取该应用的名字、发布版本号、内部版本号标识、包名相关信息。

2.插件使用

首先,我们需要在自己的js文件中引入该插件,即“require(“cordova!cordova-plugin-app-version”);”在此不做过多叙述了。

然后就是调用插件的API了,该插件提供了四个接口,分别是获取APP名称,包名,发布版本号,内部版本号。代码如下:


//回调方法
Model.prototype.callBack = function(){
	this.success = function (result) {
		justep.Util.hint(result);
	};
	this.error = function () {
		justep.Util.hint("获取失败");
	};
};

//获取APP的名字
Model.prototype.nameBtnClick = function(event){
	cordova.getAppVersion.getAppName(this.success,this.error);
};

//获取APP的包名
Model.prototype.budleIDBtnClick = function(event){
	cordova.getAppVersion.getPackageName(this.success,this.error);
};

//获取APP的发布版本号
Model.prototype.appNumberClick = function(event){
	cordova.getAppVersion.getVersionNumber(this.success,this.error);
};

//获取APP内部版本号标识
Model.prototype.appCodeClick = function(event){
	cordova.getAppVersion.getVersionCode(this.success,this.error);
};