本篇文章由:http://xinpure.com/cordova-quick-start-recording/html
Cordova 官网入门文档 Get Started Fast,言简意该、通俗易懂。android
在此仅记录过程及安装时遇到的问题,作个记念什么的也好。ios
彻底就是根据官方文档,敲敲命令而已git
xinpureZhu:cordova xinpure$ sudo npm install -g cordova
xinpureZhu:cordova xinpure$ cordova create MyApp Creating a new cordova project.
Cordova 现支持的平台 amazon-fireos
, android
, blackberry10
, browser
, firefoxos
, ios
, osx
, webos
github
这里便随着文档,选择了 browser
web
xinpureZhu:cordova xinpure$ cd MyApp/ xinpureZhu:MyApp xinpure$ ls config.xml hooks platforms plugins www xinpureZhu:MyApp xinpure$ cordova platform Installed platforms: Available platforms: amazon-fireos, android, blackberry10, browser, firefoxos, ios, osx, webos xinpureZhu:MyApp xinpure$ cordova platform add browser Adding browser project... Creating Browser project. Path: platforms/browser Discovered plugin "cordova-plugin-whitelist" in config.xml. Installing to the project Fetching plugin "cordova-plugin-whitelist@1" via npm Installing "cordova-plugin-whitelist" for browser
xinpureZhu:MyApp xinpure$ cordova run browser Running command: /Project/cordova/MyApp/platforms/browser/cordova/run Static file server running on port 8000 (i.e. http://localhost:8000) CTRL + C to shut down Static file server running @ http://localhost:8000/index.html CTRL + C to shut down Executing command: open -n -a "Google Chrome" --args --user-data-dir=/tmp/temp_chrome_user_data_dir_for_cordova http://localhost:8000/index.html
到此,Cordova 快速入门便结束了,确实比较简单的chrome
WebApp 固然仍是要在手机上跑起来才到位,这里使用 ios
尝尝鲜apache
xinpureZhu:MyApp xinpure$ cordova platform add ios Adding ios project... iOS project created with cordova-ios@3.9.1 Installing "cordova-plugin-whitelist" for ios
xinpureZhu:MyApp xinpure$ cordova run ios Running command: /Project/cordova/MyApp/platforms/ios/cordova/run ios-sim was not found. Please download, build and install version 3.0.0 or greater from https://github.com/phonegap/ios-sim into your path, or do 'npm install -g ios-sim' ERROR running one or more of the platforms: Error: /Project/cordova/MyApp/platforms/ios/cordova/run: Command failed with exit code 2 You may not have the required environment or OS to run this project
执行命令终于不是那么顺畅了,缺乏 ios-sim
模块 (解决方法已清楚的提示,因此也不算是问题啦)npm
按提示执行命令:api
xinpureZhu:MyApp xinpure$ sudo npm install -g ios-sim
安装完成后再从新执行启动命令:
xinpureZhu:MyApp xinpure$ cordova run ios Running command: /Project/cordova/MyApp/platforms/ios/cordova/run simctl was not found. Check that you have Xcode 6.x installed: xcodebuild --versionCheck that you have Xcode 6.x selected: xcode-select --print-path ERROR running one or more of the platforms: Error: /Project/cordova/MyApp/platforms/ios/cordova/run: Command failed with exit code 2 You may not have the required environment or OS to run this project
好吧,看到这个错误提示,个人心里是茫然的。
我使用的是 Mac OS X EI Capitan, Xcode 也更新到了 7.0.1, 何故如此?
再次 查看文档后发现不一样于 bowser
平台,ios
平台须要先 build
其实以前也看到过 build
这一操做,可是思惟定势,想固然的觉得 cordova run
会同时执行 cordova build
,然而并非。
xinpureZhu:MyApp xinpure$ cordova platform ls Installed platforms: browser 4.0.0, ios 3.9.1 Available platforms: amazon-fireos, android, blackberry10, firefoxos, osx, webos xinpureZhu:MyApp xinpure$ cordova build ios ...此处省略一连串 Build 信息.. ** BUILD SUCCEEDED **
出现了 SUCCEEDED
显然已经成功了
xinpureZhu:MyApp xinpure$ cordova emulate ios
此处依然省略大量, 启动时的编译信息。启动成功也会 SUCCEEDED
提示,同时 Xcode 仿真器也会启动并打开 App
虽然官方已经提供了详细的说明文档,文档也简单易懂,可是无论多简单仍是要亲自动手敲敲命令,说不定就会出现一些意想不到的问题。