如何获取在config.xml中定义的版本字符串 [英] How do I get the version string I defined in the config.xml

查看:109
本文介绍了如何获取在config.xml中定义的版本字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何确定我的Cordova应用程序是哪个版本?我需要该信息以在关于"屏幕中显示它.

How do I find out, which version my Cordova app is? I need that information to display it in an About screen.

是否可以读取config.xml并获取我已经在此文件中维护的版本字符串?

Is it possible to read the config.xml and get the version string, which i am already maintaining in this file?

<widget ... version="0.0.1" ...

我想要一个解决方案,无需在代码中的多个位置维护应用程序的版本号.另外,我也不想为此目的使用插件,因为大多数插件都不支持Android,iOS和浏览器作为平台.

I would like to have a solution where I do not have to maintain the app's version number in several places in the code. Also, I do not want a plugin for that purpose, because most plugins do not support Android, iOS and browser as platforms.

还是我忽略了核心插件属性?

Or am I overlooking a core plugin attribute?

还是有一种解决方案,其中我维护一个文件,该文件不是config.xml,而config.xml从该文件获取版本信息?

Or is there a solution where I maintain one file, which is no the config.xml, and the config.xml gets the version information from that file?

您如何在应用的关于"屏幕中实现显示版本信息"?任何提示表示赞赏.

How are you implementing "display version info" in your app's about screen? Any hint is appreciated.

我的Cordova版本是:

My Cordova version is:

>cordova -v
4.2.0

推荐答案

如果您不希望使用任何第三方插件来实现此目的,那么我觉得Cordova钩子是可行的方法.您可以使用before_build挂钩从config.xml文件中读取版本,并在应用程序中使用该版本.

If you are not interested in using any third party plugin to achieve this, then I feel Cordova hooks is the way to go. You can come up with a before_build hook to read the version from config.xml file and make use of the same in app.

幸运的是,在以下

Fortunately, this hook is readily available for you in the following link where they are reading version from config.xml and injecting it as a dependency wherever required.

建议您还查看

Suggest you to also have a look at the official documentation of cordova hooks for better understanding.

实际上,您还可以尝试从config.xml中读取版本信息,并将其直接放在您可以在index.html中创建的某个占位符中以显示版本信息.这可以在cordova使用钩子进行构建之前完成,而钩子又使用Windows批处理文件来执行文件操作.您可以在我的 github页面中签出使用批处理文件的cordova hook的工作示例.

In fact, you can also try out reading version info from config.xml and directly put it in some placeholder that you can create in your index.html to display the version info. This can be done before cordova build using hooks which in turn uses windows batch file that does the file operations. You can checkout a working sample of cordova hook that uses batch file in my github page.

这篇关于如何获取在config.xml中定义的版本字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆