国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

cordova入門基礎教程及使用中遇到的一些問題總結

2019-11-19 14:56:19
字體:
來源:轉載
供稿:網友

前言

現在做項目為了節約成功,適配多平臺 cordova不為是一個很好的選擇。個人覺得以后也許是一個趨勢!像一些知名的APP  比如支付寶  淘寶 好多都大量集成了HTML5 頁面!像我們公司現在的APP 大多都是h5頁面 感覺原生都沒什么事情做了。可想而知學習cordova的重要性!

簡介

Cordova提供了一組設備相關的API,通過這組API,移動應用能夠以JavaScript訪問原生的設備功能,如攝像頭、麥克風等。Cordova還提供了一組統一的JavaScript類庫,以及為這些類庫所用的設備相關的原生后臺代碼。Cordova支持如下移動操作系統:iOS, Android,ubuntu phone os, Blackberry, Windows Phone, Palm WebOS, Bada 和 Symbian。

入門第一步:下載資源庫并集成到項目中來

去下載cordova 庫的源碼 可以去github上下載 也可以去官網下載。其實官網上的代碼也是放到github上的!

官方網站:http://cordova.apache.org/

github資源下載地址:https://github.com/apache/cordova-ios   

本地下載地址:http://xiazai.VeVB.COm/201711/yuanma/cordova-ios(VeVB.COm).rar

使用 CocoaPods進行第三方庫的管理 我之前用的是cordova3.8.0 前幾天不久更新到了4.0.1 。 4.0.1 只支持8.0以上  以下的你用CocoaPods 更新會提示錯誤!注意一下就可以了!

platform :ios, '8.0'

pod 'Cordova', '~> 4.0.1'

入門第二步:如何在項目中正確的集成 cordova4.0.1 庫

1. 配置 Config.xml   很重要

Config.xml is a global configuration file that controls many aspects of a cordova application's behavior. This platform-agnostic XML file is arranged based on the specification, and extended to specify core Cordova API features, plugins, and platform-specific settings.For projects created with the Cordova CLI (described in The Command-Line Interface), this file can be found in the top-level directory:

大致意思就是: config.xml 是一個全局配置文件,控制一個cordova應用行為的許多方面。這種平臺無關的XML文件是基于w3c'spackaged Web應用程序設置(widgets)規范,并擴展到指定核心cordovaAPI功能,插件和平臺的具體設置。與科爾多瓦CLI創建的項目(描述在命令行界面)

http://cordova.apache.org/docs/en/6.x/config_ref/index.html 官方詳解

2. 顯示html5頁面需要一個容器 在這里使用CDVViewController類 進行html5的顯示以及控制 當然也可以自定義一個容器繼承CDVViewController類做一些定制功能。

如何使用如下:

self.cordovaManageVC= [[CordovaManageVCalloc]init];self.cordovaManageVC.startPage=@"http://www.baidu.com";[self.navigationControllerpushViewController:self.cordovaManageVCanimated:YES];

3. 設置用戶代理

- (instancetype)init {self= [superinit];if(self!=nil) {//設置用戶代理 如不設置無法調用與H5定制的JavaScript方法進行交互NSString* original = [CDVUserAgentUtiloriginalUserAgent];NSString* userAgent = [originalstringByAppendingString:@"delegateUserName"];self.baseUserAgent= userAgent;}returnself;}

4. 自定義插件 需要使用到 cordova的CDVPlugin類 用子類來集成CDVPlugin 

/***返回控件**@param command*/- (void)back:(CDVInvokedUrlCommand*)command;

定制完成之后需要在confing.xml 進行配置 

以上就是cordova 最基本的用法了;

使用 Cordova 遇到的一些問題

問題一

問題

[Error: Failed to find 'ANDROID_HOME' environment variable. Try setting setting it manually. Failed to find 'android' command in your 'PATH'. Try update your 'PATH' to inclde path to valid SDK directory.]ERROR building one of the platforms: Error: cmd: Command failed with exit code

解決辦法

ANDROID_HOME=D:/apps/Android/sdkPATH=%PATH%;%ANDROID_HOME%/tools;%ANDROID_HOME%/platform-tools

問題二

問題

Error: Could not find an installed version of Gradle either in Android Studio,or on your system to install the gradle wrapper. Please include gradlein your path, or install Android Studio

解決辦法

https://services.gradle.org/distributions/ 下載最新gradle包并安裝。

ANDROID_HOME=/home/kongxx/Android/SdkGRADLE_HOME=/apps/gradle-3.2.1PATH=$PATH:$ANDROID_HOME/tools/:$ANDROID_HOME/platform-tools:$GRADLE_HOME/bin

問題三

問題

使用 “cordova build android” 打包的時候報錯:Error: Could not find gradle wrapper within Android SDK.

$ cordova build androidCHCP plugin after prepare hook: config-file set to http://www.tjdr.info/EWT/chcp.jsonANDROID_HOME=/home/kongxx/Android/SdkJAVA_HOME=/opt/jdk8Error: Could not find gradle wrapper within Android SDK. Might need to update your Android SDK.Looked here: /home/kongxx/Android/Sdk/tools/templates/gradle/wrapper

解決辦法

查看了一下 /home/kongxx/Android/Sdk/tools/templates/gradle/wrapper 目錄,目錄確實不存在,于是檢查了一下 android-studio 環境,發現可以在 plugins/android/lib/templates 目錄下包括上面的內容,于是,果斷copy之。

$ cp -rf android-studio/plugins/android/lib/templates /home/kongxx/Android/Sdk/tools/

問題四

問題

使用Cordova打包時報錯:Error: spawn EACCES

$ cordova build androidCHCP plugin after prepare hook: config-file set to http://www.tjdr.info/EWT/chcp.jsonANDROID_HOME=/home/kongxx/Android/SdkJAVA_HOME=/opt/jdk8Subproject Path: CordovaLibError: spawn EACCES

解決辦法

sudo chmod -Rf 755 ~/Android

問題五

問題

在 cordova 中使用瀏覽器測試的時候,默認啟動的是 google-chrome 瀏覽器,比如:

cordova run browser

解決辦法

可以使用

主站蜘蛛池模板: 巴青县| 吉林市| 黄骅市| 芦溪县| 毕节市| 津市市| 龙口市| 抚宁县| 民乐县| 海安县| 府谷县| 金华市| 奉节县| 屏边| 稷山县| 江阴市| 南宁市| 都江堰市| 石家庄市| 青冈县| 鲜城| 津市市| 湟中县| 称多县| 仪征市| 河北区| 土默特右旗| 称多县| 柏乡县| 昌邑市| 堆龙德庆县| 安庆市| 石景山区| 读书| 哈密市| 泰顺县| 清水县| 拜城县| 湘西| 察隅县| 嘉峪关市|