前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Cordova(工具)- Config.xml详解

Cordova(工具)- Config.xml详解

作者头像
安德玛
发布2022-03-09 08:21:40
1.1K0
发布2022-03-09 08:21:40
举报
文章被收录于专栏:Cordova封装H5 APPCordova封装H5 APP

Config.xml是什么,有什么作用

Config.xml是 cordova项目的一份全局性配置文件 能够控制整个项目的一些全局性配置 为了方便cordova CLI 的使用,config.xml放在了这里 , 其实就是项目根目录下

代码语言:javascript
复制
 app/config.xml。

需要注意的是3.3.1-0.2.0版本之前,该文件存在于app/www/ config.xml中,而且这里有它仍然支持。 当使用CLI来建一个项目,该文件版本进行被动复制到不同的平台子目录。

一个新项目的config.xml文件

代码语言:javascript
复制
<?xml version='1.0' encoding='utf-8'?>
<widget id="io.cordova.hellocordova" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>HelloCordova</name>
    <description>
        A sample Apache Cordova application that responds to the deviceready event.
    </description>
    <author email="dev@cordova.apache.org" href="http://cordova.io">
        Apache Cordova Team
    </author>
    <content src="index.html" />
    <plugin name="cordova-plugin-whitelist" spec="1" />
    <access origin="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <platform name="android">
        <allow-intent href="market:*" />
    </platform>
    <platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
    </platform>
</widget>

widget

config.xml文件文档的根元素

下面是widget,属性

属性

描述

id(string)

必须字段, 应用程序的标识

version(string)

必须字段, 应用程序的版本 。这个版本号对应项目的实际版本号

android-versionCode(string)

安卓的版本设置

defaultlocale

iOS的设置默认语言标识

ios-CFBundleVersion(string)

ios版本的bundleVersion版本设置

osx-CFBundleVersion(string)

mac版本的bundleVersion版本号设置

windows-packageVersion(string)

window - bundle设置

packageName(string)

Windows包的包名

xmlns(string)

必须字段 ,直接默认http://www.w3.org/ns/widgets 就好 ,不用管

xmlns:cdv(string)

必须字段 , 直接默认http://cordova.apache.org/ns/1.0 就好,不用管

除了属性,还可以包含以下标签,控制对应的功能

标签

描述

属性

<name>HelloCordova</name>

指定应用程序的名称,这个名字出现在设备的屏幕上,例如这里,手机屏幕会显示这个app叫HelloCordova

description

指定app描述信息(应用商店上显示)

author

联系人信息(应用商店上显示)

email(string) - 必须,邮箱 : href(string) - 必须,作者主页

content

应用程序的起始页面。默认值是index.html的

src(string) - 必须,页面路径

access

定义白名单用的,*号代表任何ip都能访问,也可以定义具体的域名 。

origin(string) - 必须,url

allow-navigation

用于顶级导航跳转,适用于 WebView, 详细用法参考 cordova-plugin-whitelist

href(string) - 必须,URL

allow-intent

用于应用控制允许要求系统打开, 不填等于默认打开

href(string) - 必须,URL

engine

用于恢复版本的

name(string) - 必须, 要恢复的平台的名称 spec(string) - 必须,要恢复的平台版本

plugin

指定哪些插件在准备还原的细节。当使用--save标志添加一个插件,这个元素被自动添加到项目的config.xml。

preference

设置各种选项对名称/值属性。每个首选项的名称是区分大小写的。许多偏好是独一无二的特定的平台,而详细的每一个代表的意义,请参考官方文档,太多不一一列举了

下面的表,列出具体的所有名称

feature

用来指定什么某些插件参数,如:什么包检索来自插件代码,并确定是否插件代码是网页视图的初始化期间进行初始化。

platform

当使用CLI来构建应用程序,有时需要以指定特定于特定的平台的偏好或其他元素。使用元素来指定应该只出现在一个 platform-specific -config.xml文件中的配置。

hook

cordova某些行为发生时, 调用自定义脚本, 例如 <hook type="after_plugin_install" src="scripts/afterPluginInstall.js" /> 当插件安装完成后,执行afterPluginInstall.js

代码语言:javascript
复制
<preference name="DisallowOverscroll" value="true"/>
<preference name="Fullscreen" value="true" />
<preference name="BackgroundColor" value="0xff0000ff"/>
<preference name="HideKeyboardFormAccessoryBar" value="true"/>
<preference name="Orientation" value="landscape" />

<!-- iOS only preferences -->
<preference name="EnableViewportScale" value="true"/>
<preference name="MediaPlaybackAllowsAirPlay" value="false"/>
<preference name="MediaPlaybackRequiresUserAction" value="true"/>
<preference name="AllowInlineMediaPlayback" value="true"/>
<preference name="BackupWebStorage" value="local"/>
<preference name="TopActivityIndicator" value="white"/>
<preference name="SuppressesIncrementalRendering" value="true"/>
<preference name="GapBetweenPages" value="0"/>
<preference name="PageLength" value="0"/>
<preference name="PaginationBreakingMode" value="page"/>
<preference name="PaginationMode" value="unpaginated"/>
<preference name="UIWebViewDecelerationSpeed" value="fast" />
<preference name="ErrorUrl" value="myErrorPage.html"/>
<preference name="OverrideUserAgent" value="Mozilla/5.0 My Browser" />
<preference name="AppendUserAgent" value="My Browser" />
<preference name="target-device" value="universal" />
<preference name="deployment-target" value="7.0" />
<preference name="CordovaWebViewEngine" value="CDVUIWebViewEngine" />
<preference name="SuppressesLongPressGesture" value="true" />
<preference name="Suppresses3DTouchGesture" value="true" />

<!-- Android only preferences -->
<preference name="KeepRunning" value="false"/>
<preference name="LoadUrlTimeoutValue" value="10000"/>
<preference name="InAppBrowserStorageEnabled" value="true"/>
<preference name="LoadingDialog" value="My Title,My Message"/>
<preference name="ErrorUrl" value="myErrorPage.html"/>
<preference name="ShowTitle" value="true"/>
<preference name="LogLevel" value="VERBOSE"/>
<preference name="AndroidLaunchMode" value="singleTop"/>
<preference name="DefaultVolumeStream" value="call" />
<preference name="OverrideUserAgent" value="Mozilla/5.0 My Browser" />
<preference name="AppendUserAgent" value="My Browser" />

<!-- Windows only preferences -->
<preference name="windows-phone-target-version" value="8.1" />
<preference name="windows-target-version" value="8.1" />
<preference name="Windows.Universal" value="10.0.10240.0" />
<preference name="WindowsDefaultUriPrefix" value="ms-appx://" />
<preference name="Windows.Mobile-MaxVersionTested" value="10.0.10031.0" />
<preference name="Windows.Universal-MinVersion" value="10.0.0.0" />
<preference name="WindowsStoreIdentityName" value="Cordova.Example.ApplicationDataSample" />
<preference name="WindowsStorePublisherName" value="CN=Contoso Corp, O=Contoso Corp, L=Redmond, S=Washington, C=US" />
<preference name="WindowsToastCapable" value="true" />
<preference name="uap-target-min-version" value="10.0.10586.0" />

<!-- BlackBerry only preferences -->
<preference name="ChildBrowser" value="disable"/>
<preference name="PopupBlocker" value="enable"/>
<preference name="WebSecurity" value="disable"/>

<!-- OS X only preferences -->
<preference name="HideMousePointer" value="5"/>
<preference name="OSXLocalStoragePath" value="~/.myapp/database"/>
<preference name="WindowSize" value="800x400"/>
<preference name="EnableWebGL" value="true"/>

本文系转载,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文系转载前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Config.xml是什么,有什么作用
  • widget
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档