cordova config.xml配置知识点

2 篇文章 0 订阅
1 篇文章 0 订阅

Config.xml配置

widght

属性(类型)描述
id(string)必须。指定应用程序的反向域标识符
version(string)必须。完整版本号,以主要/次要/补丁符号表示
packageName(字符串)默认值Cordova,程序包名
xmlns(字符串)config.xml的必须命名空间
xmlns:cdv(字符串)必须。命名空间前缀

示例

<!-- Android -->
<widget id="io.cordova.hellocordova" version="0.0.1" android-versionCode="13" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
</widget>

<!-- iOS -->
<widget id="io.cordova.hellocordova" version="0.0.1" ios-CFBundleVersion="0.1.3" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
</widget>

<!-- Windows -->
<widget id="io.cordova.hellocordova" version="0.0.1" windows-packageVersion="0.1.3" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
</widget>

<!-- OS X -->
<widget id="io.cordova.hellocordova" version="0.0.1" osx-CFBundleVersion="0.1.3" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
</widget>

name

指定应用的正式名称,如:

<widget ...>
   <name>exampleName</name>
</widget>
  • short name(简称)
    • 指定应用程序的可选显示名称。因屏幕空间有限时可显示。
      示例:
        <widget ...>
           <name short="HiCdv">HelloCordova</name>
        </widget>
    

description(描述)

指定可能出现在应用商店列表中的元数据,示例:

  <widget ...>
     <description>A sample Apache Cordova application</description>
  </widget>

author(作者)

指定可能出现在商店列表中的联系信息

属性描述
email(string)必须。作者邮箱
href(string)必须。作者网站

示例

<widget ...>
<author email="dev@cordova.apache.org" href="http://cordova.io"></author>
</widget>

content

定义应用启动的其实页面,默认为index.html,出现在www目录下

属性描述
src(string)必须。定义应用程序的起始页面。默认为index.html

示例:

<widget ...>
   <content src="startPage.html"></content>
</widget>

access

定义允许应用程序通信的一组外部域。默认允许访问任何服务器

属性描述
origin(string)必须。定义允许应用程序通信的一组外部域

示例:

<widget ...>
   <access origin="*"></access>
</widget>

<widget ...>
   <access origin="http://google.com"></access>
</widget>

allow-navigation

控制WebView本身可以导航的URL。仅适用于顶层导航

属性描述
href(string)必须。定义允许应用程序导航到的外部域的集合

示例:

<!-- Allow links to example.com -->
<allow-navigation href="http://example.com/*" />

<!-- Wildcards are allowed for the protocol, as a prefix to the host, or as a suffix to the path -->
<allow-navigation href="*://*.example.com/*" />

allow-intent

控制允许应用要求系统打开的URL。默认不允许

属性描述
href(string)必须。定义允许应用程序要求系统打开的URL

示例:

<!-- Allow links to example.com -->
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />

edit-config

对xml元素的属性进行修改,而不是将新的子项附加到xml文档树中

属性描述
file(string)要修改的文件以及相对于Cordova项目根目录的路径。目标可以包含通配符(*)元素
target(string)Xpath选择器,该选择器引用目标元素以对其属性修改。
model(string)属性修改模式类型。merge:如果元素已存在,替换,overwrite:用指定属性替换目标元素中的所有属性
  • file目录不存在、target元素不存在都会不执行修改
  • 示例:
<!-- plugin-1 -->
<edit-config file="AndroidManifest.xml" target="/manifest/uses-sdk" mode="merge">
    <uses-sdk android:minSdkVersion="16" android:maxSdkVersion="23" />
</edit-config>
<edit-config file="AndroidManifest.xml" target="/manifest/application/activity[@android:name='MainActivity']" mode="overwrite">
    <activity android:name="MainActivity" android:label="NewLabel" android:configChanges="orientation|keyboardHidden" />
</edit-config>
  • 管理edit-config冲突
    • 如果edit-cofnig有冲突或插件怪异,须先解决,要么删除重新添加,要么 --force强制添加,还原其他插件冲突修改

config-file

标识要修改的基于XML的配置文件,在该文档中应进行的修改及应修改的内容。仅允许将新的子项附加到xml文档树中。

属性描述
target(string)要修改的文件以及相对于Cordova项目根目录的路径。目标可以包含通配符(*)元素
parent(string)Xpath选择器,引用要添加到配置文件中的元素的父级。
after(string)在可接受同级之后添加XML代码片段
device-target(string)允许值:win、phone、all
version(string)当影响meta-name时适用package.appxmanifest,此属性指示特定Windows版本的应用程序清单应仅针对与指定版本字符串匹配的版本进行更改。值可以是任何有效的节点语义版本范围字符串。

例子:

对于XML<config-file target="AndroidManifest.xml" parent="/manifest/application">
    <activity android:name="com.foo.Foo" android:label="@string/app_name">
        <intent-filter>
        </intent-filter>
    </activity>
</config-file>
对于plist:

<config-file target="*-Info.plist" parent="CFBundleURLTypes">
    <array>
        <dict>
            <key>PackageName</key>
            <string>$PACKAGE_NAME</string>
        </dict>
    </array>
</config-file>
对于特定于Windows的属性:

<config-file target="package.appxmanifest" parent="/Package/Capabilities" versions="&lt;8.1.0">
    <Capability Name="picturesLibrary" />
    <DeviceCapability Name="webcam" />
</config-file>
<config-file target="package.appxmanifest" parent="/Package/Capabilities" versions=">=8.1.0" device-target="phone">
    <DeviceCapability Name="webcam" />
</config-file>

engine

指定在准备期间还原哪个平台的详细信息

属性描述
name(string)必须。平台名称
spec(string)必须。要还原的平台的必须详细信息,可以是major.minor.patch版本号,包含插件的目录或指向git存储库的URL。此信息将用于检索要从NPM,本地目录或git存储库还原的插件代码。

示例:

<engine name="android" spec="https://github.com/apache/cordova-android.git#5.1.1" />
<engine name="ios" spec="^4.0.0" />

plugin

指定在准备期间还原哪些插件的详细信息。使用–save标志添加该插件时,此元素会自动添加到项目的元素中。

属性描述
name(string)必须。插件名称
spec(string)必须。要还原的插件的详细信息可以是major.minor.patch版本号,包含插件的目录或指向git存储库的URL。此信息将用于检索要从NPM,本地目录或git存储库还原的插件代码。

示例:

<plugin name="cordova-plugin-device" spec="^1.1.0" />
<plugin name="cordova-plugin-device" spec="https://github.com/apache/cordova-plugin-device.git#1.0.0" />

variable

保留在准备期间还原插件时使用的CLI变量的值。使用–save标志添加使用CLI变量的插件时,将添加此元素

  • 注意:仅当在准备期间将插件恢复到项目时才使用此值。不会更改当前项目插件使用的值。
属性描述
name(string)必须。CLI变量的必须名称。只能包含大写字母、数字和下划线
value(string)必须。准备期间还原父插件时使用的CLI变量的必须值

示例:

<plugin name="cordova-plugin-device" spec="^1.1.0">
    <variable name="MY_VARIABLE" value="my_variable_value" />
</plugin>

preference

将各种选项设置为一对名称/值属性。名称不区分大小写。

  • 平台特有首选项:

    属性描述
    AllowInlineMediaPlayback(boolean)默认false。是否允许HTML5媒体播放使用浏览器提供的控件而不是本机控件在屏幕布局中内联显示。将playsinline属性添加到任何元素。注意:在iOS 10之前,元素需要改用webkit-playsinline属性名称。
    AndroidLaunchMode(string)默认是singleTop。值:standard、singleTop、singleTask、singleInstance。设置Activity启动模式
    android-maxSdkVersion(integer)默认值未指定。设置AndroidMainifedt.xml中use-sdk标签maxVersion属性值
    android-minSdkVersion(integer)默认值取决于cordova-adnroid版本。设置AndroidMainifedt.xml中use-sdk标签minSdkVersion属性值
    androrid-targetSdkVersion(integer)默认值取决于cordova-android版本。设置AndroidMainifedt.xml中use-sdk标签targetSdkVersion属性值
    BackGroundColor(string)设置应用程序的背景色
    BackupWebStorage(string)默认值cloud。允许值:node、local、cloud。cloud:允许web存储数据通过iCloud本分。local:允许通过iTunes同步进行本地备份。none:不允许备份

示例

<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" />
  • 这里只列举出几个首选项,具体请参照官网。

feture(特征)

param(参数)

platform

使用ClI构建应用程序时,有时有必要指定特定平台首选项或其他元素。

属性描述
名称(string)必须。定义其首选项的平台

示例:

<platform name="android">
   <preference name="Fullscreen" value="true" />
</platform>

hook

自定义脚本

属性描述
类型(string)必须。指定将在其中调用自定义脚本的操作
src(string)必须。指定发生特定操作时要调用的脚本的位置

示例:

<hook type="after_plugin_install" src="scripts/afterPluginInstall.js" />

resource-file

将资源文件安装到您的平台中。cordova-ios4.4.0以上或者cordova-android@6.2.1

属性描述
src(string)必须。文件相对于的必须位置config.xml
target(string)必须。文件复制目标路径

例子:

<resource-file src="FooPluginStrings.xml" target="res/values/FooPluginStrings.xml" />
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值