Cordova 3.x 基礎(5) -- 設定檔config.xml

來源:互聯網
上載者:User

標籤:

原文:http://rensanning.iteye.com/blog/2019331

首先要注意的是:從3.3版本以後已經把www/config.xml移動到了根目錄下。 

在config.xml中定義的東西應該適應所有平台。在build工程的是時候,會看到“Generating config.xml from defaults for platform "android"”這樣的字樣,他會產生各個平台的config.xml。 

產生的檔案: 

  • Android:MyProject/platforms/android/res/xml/config.xml.
  • iOS:MyProject/platforms/ios/MyProject/config.xml.


產生的config.xml當然會根據平台不同加入不同的內容。 
比如Android下就就在config.xml添加了以下內容: 

Xml代碼  
  1. <preference name="loglevel" value="DEBUG" />  
  2. <feature name="App">  
  3.     <param name="android-package" value="org.apache.cordova.App" />  
  4. </feature>  



config.xml檔案的Scheme基於W3C的Widgets定義。 
基本構造: 

Xml代碼  
  1. <widget>  
  2.   <name></name>  
  3.   <preference />  
  4.   <feature>  
  5.     <param />  
  6.   </feature>  
  7.   <access />  
  8.   <content />  
  9. </widget>  



preference: 
選項設定。應用運行時的一些參數,根據平台設定的內容不同。 
Android設定:http://cordova.apache.org/docs/en/3.4.0/guide_platforms_android_config.md.html 
iOS設定:http://cordova.apache.org/docs/en/3.4.0/guide_platforms_ios_config.md.html 

access: 
域限制設定。應用中如果讀取其他域中的HTML檔案,而該檔案中如果使用了cordova.js,那麼他就能訪問手機的本地功能。遵守W3C Widget Access規範。 
可以設定多個: 
<access origin="http://example.com" /> 
<access origin="http://foobar.example.com" /> 
也可以使用萬用字元: 
<access origin="http://*.example.com" /> 
預設可以訪問任何域。 
<access origin="*" /> 

feature: 
應用中使用了哪些Native功能,Cordova在運行時會掃描feature屬性就知道哪些Plugin是有效。在執行cordova plugin add的時候會自動添加feature。 
比如: 

引用cordova plugin add org.apache.cordova.camera 
cordova build


platforms/android/res/xml/config.xml中就會多了以下內容: 

Xml代碼  
  1. <feature name="Camera">  
  2.     <param name="android-package" value="org.apache.cordova.camera.CameraLauncher" />  
  3. </feature>  



content: 
應用的入口檔案。預設是index.html。 

其他: 
widget的id屬性,Android的話就是應用的package名,iOS是AppID。 
widget的version屬性就是應用的版本號碼(android:versionName)(3.5版本中可以android-versionCode="10")。 
name標籤就是應用的名字(把檔案儲存為UTF-8支援中文)。 
 

***在"cordova create"的時候,App名不能全部是分英文字母,比如,"我的應用程式"。必須包含英文字母,因為CordovaCLI要用來產生MainActivity的Class名. 

***這個問題最新版已經Fixed。CB-6511 Fixes build for Android when app name contains unicode characters. 


設定版本 
iOS 
Version (CFBundleShortVersionString) 
Build (CFBundleVersion) 
Android 
android:versionName 
android:versionCode 

應用程式名稱的國際化 
iOS 
CFBundleDisplayName = "Sample App Name"; 
Android 
strings.xml app_name = "Sample App Name";

Cordova 3.x 基礎(5) -- 設定檔config.xml

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.