2017-05-12 132 views
1

我想要在我的iPhone上運行Cordova內部的簡單JavaScript應用程序。 該項目在模擬器內工作得很好,但在手機上運行時會顯示一個奇怪的屏幕。科爾多瓦WKWebView白色屏幕

這是我的config.xml文件:

<widget 
    id="com.landonschropp.tictactoe" 
    version="1.0.0" 
    xmlns="http://www.w3.org/ns/widgets" 
    xmlns:cdv="http://cordova.apache.org/ns/1.0"> 

    <name>Tic-Tac-Toe</name> 
    <description>An awesome little tic-tac-toe game.</description> 
    <author email="[email protected]" href="https://landonschropp.com">Landon Schropp</author> 

    <content src="http://localhost:8080" /> 
    <access origin="*" /> 
    <allow-navigation href="http://localhost:8080/*" /> 

    <feature name="CDVWKWebViewEngine"> 
    <param name="ios-package" value="CDVWKWebViewEngine" /> 
    </feature> 

    <preference name="CordovaWebViewEngine" value="CDVWKWebViewEngine" /> 

    <plugin name="cordova-plugin-statusbar" spec="^2.2.3" /> 
    <plugin name="cordova-plugin-whitelist" spec="^1.3.2" /> 
    <plugin 
    name="cordova-plugin-wkwebview-engine" 
    spec="git+https://github.com/driftyco/cordova-plugin-wkwebview-engine.git" /> 

    <engine name="ios" spec="^4.4.0" /> 
</widget> 

和我的package.json文件:

{ 
    "name": "tic_tac_toe", 
    "description": "A simple tic-tac-toe game", 
    "dependencies": { 
    "axios": "^0.16.1", 
    "babel-preset-es2015": "^6.24.1", 
    "babel-preset-stage-2": "^6.24.1", 
    "cheerio": "^0.22.0", 
    "cordova": "^7.0.0", 
    "cordova-ios": "^4.4.0", 
    "cordova-plugin-statusbar": "^2.2.3", 
    "cordova-plugin-whitelist": "^1.3.2", 
    "cordova-plugin-wkwebview-engine": "git+https://github.com/driftyco/cordova-plugin-wkwebview-engine.git", 
    "gulp": "^3.9.1", 
    "gulp-connect": "^5.0.0", 
    "gulp-file-cache": "^0.0.1", 
    "gulp-sass": "^3.1.0", 
    "gulp-sass-glob": "^1.0.8", 
    "gulp-transform": "^1.1.0", 
    "gulp-util": "^3.0.8", 
    "gulp-watch": "^4.3.11", 
    "lodash": "^4.17.4", 
    "phaser": "^2.6.2", 
    "rollup": "^0.41.6", 
    "rollup-plugin-babel": "^2.7.1", 
    "rollup-plugin-commonjs": "^8.0.2", 
    "rollup-plugin-json": "^2.1.1", 
    "rollup-plugin-node-resolve": "^3.0.0", 
    "rollup-stream": "^1.19.0", 
    "run-sequence": "^1.2.2", 
    "vinyl-source-stream": "^1.1.0" 
    }, 
    "devDependencies": { 
    "babel-register": "^6.24.1", 
    "chai": "^3.5.0", 
    "del": "^2.2.2", 
    "eslint": "^3.19.0", 
    "mocha": "^3.2.0" 
    }, 
    "cordova": { 
    "platforms": [ 
     "ios" 
    ], 
    "plugins": { 
     "cordova-plugin-whitelist": {}, 
     "cordova-plugin-wkwebview-engine": {}, 
     "cordova-plugin-statusbar": {} 
    } 
    } 
} 

要構建並運行應用程序,我執行以下操作:

  1. yarn install
  2. cordova platform add ios
  3. cordova run ios

目前,運行在手機上的應用程序,我看到下面的畫面時:

App on iPhone

+0

如果有幫助,這是一個鏈接到完整的回購:https://github.com/LandonSchropp/tic_tac_toe。 – LandonSchropp

+1

Landon,http:// localhost:8080看起來相當可疑。你確定它可以從你的手機到達嗎?如果你的Mac上有服務器,也許值得指定你的Mac的IP地址,以允許手機連接到它(如果電話和Mac在同一網絡當然) – dymv

+0

@dymv我的印象是'cordova- plugin-wkwebview-engine'插件在iPhone上運行本地服務器。不是嗎? – LandonSchropp

回答

1

如前所述dymv,這個問題很有可能是您的應用程序不能到達本地主機,因爲在這方面的「本地主機」是你的開發計算機,而不是iPhone。你可以將它部署到託管服務器解決方案並重新測試嗎?

WKWebView插件不是本地服務器,而是增強的WebView組件(WebView基本上是運行您的HTML,CSS,JavaScript代碼的應用程序中的嵌入式瀏覽器)。核心優勢是它可以更快速地處理JavaScript(速度更快!),所以您的應用程序的性能會更好。