$ sudo npm install -g phonegap 我沒有成功安裝,因而安裝的cordova $ sudo npm install -g cordova安裝完畢以後,就可使用cordova來建立PhoneGap項目。cordova是從PhoneGap提取出來的一個開源項目,在我看來,除了名字不同以外,兩者沒有什麼區別。
$ cordova create hello com.example.hello "HelloWorld" Creating a new cordova project. $ ls hellocreate後面第一個參數hello是新建的項目文件夾名稱,第二個參數com.example.hello是公司名稱,第三個參數"HelloWorld"是項目名。在當前目錄下能夠看到多了一個文件夾hello。
$ cd hello $ cordova platform add ios $ cordova prepare至此,就完成了對基於PhoneGap的Hybrid APP項目的建立工做,接下來用XCode來打開這個項目,運行iOS模擬器來檢驗這個項目可否正常運行。
$ npm install -g yo bower grunt-cli這三個工具安裝完畢以後,在以前建立的Hybrid APP項目文件夾下建立一個Web APP的目錄,好比叫yo,而後安裝用於建立基於angular的Web項目的自動生成器,並運行yeoman來建立一個Web APP項目。
$ mkdir yo $ cd yo $ npm install -g generator-angular $ yo angular項目建立完成後,檢查一下項目可否正常運行,在命令行輸入
$ grunt serve這樣就啓動了一個Web服務器來運行剛纔建立的Web APP,順利的話能夠在瀏覽器上看到這個yeoman的實例頁面。
// Copies remaining files to places other tasks can use copy: { dist: { files: [{ expand: true, dot: true, cwd: '<%= yeoman.app %>', dest: '<%= yeoman.dist %>', src: [ '*.{ico,png,txt,xml}', '.htaccess', '*.html', 'views/{,*/}*.html', 'images/{,*/}*.{webp}', 'styles/fonts/{,*/}*.*' ] }, { expand: true, cwd: '.tmp/images', dest: '<%= yeoman.dist %>/images', src: ['generated/*'] }, { expand: true, cwd: '../platforms/ios/www', dest: '<%= yeoman.dist %>/scripts', src: [ 'plugins/**', 'cordova.js', 'cordova_plugins.js' ] }] }, styles: { expand: true, cwd: '<%= yeoman.app %>/styles', dest: '.tmp/styles/', src: '{,*/}*.css' } }, // Empties folders to start fresh clean: { dist: { files: [{ dot: true, src: [ '.tmp', '<%= yeoman.dist %>/{,*/}*', '!<%= yeoman.dist %>/.git{,*/}*' ] }] }, server: '.tmp', options: { force: true } },4,修改index.html,在angular的引用以前添加對cordova.js的引用
<script type="text/javascript" src="scripts/cordova.js"></script>5,在命令行運行grunt build,打包整個Web APP項目,而後拷貝yo/dist下全部文件到Hybrid APP項目的www目錄下
$ grunt build6,來到Hybrid APP項目的根目錄,在命令行運行cordova prepare
$ cordova prepare7,用Xcode打開Hybrid APP項目,運行iOS模擬器,能夠看到Web APP已經成功的在iOS上運行了。
echo '### Sync APP to Platforms ###' echo 'Building web APP...' echo 'Please be patient, it may take several minutes' grunt build sourceDir="dist" targetDir="../www" allFiles="/*" if [ -d $sourceDir ] then if [ ! -d $targetDir ] then mkdir -p $targetDir fi echo 'Copying source files to www/' cp -r $sourceDir$allFiles $targetDir echo 'Calling cordova prepare' cd .. cordova prepare echo 'All done' else echo 'Err: The source directory "dist" doesnot exist, use command "grunt build" to generate it firstly' fi
但想要開發高效率的應用,公認仍是作原生開發更好,iOS原生應用開發入門教程推薦王寒的編纂的《從零開始學iOS7開發系列》,教程寫的很是生動易懂,文章裏的例子也頗有表明性,仔細學習和琢磨以後能夠觸類旁通開發本身的應用。其實Hybrid APP開發早已經不限於移動平臺了,我最先接觸到的Hybrid APP是家用主機平臺,在XBOX ONE上,微軟也實現了供JavaScript調用的XBOX系統API,將Web APP經過Visual Studio打包後發佈到主機上就能夠運行。既然HTML5和CSS3在製做用戶界面上巨大的潛力,採用Hybrid APP方式確實能夠極大的幫助Web開發人員開發瀏覽器平臺之外的應用。 javascript