2017-06-12 81 views
3

我目前正在一个简单的应用程序,其中有一个HTML部分使用web视图。Nativescript + iOS的webview +本地文件

的内容是在一个应用程序/网络文件夹,我访问他们从一个“home.ts”组件像这样的东西在HTML

<GridLayout 
    class="main-layout" 
    columns="*" 
    rows="*" 
> 
    <WebView 
     src="~/www/index.html" 
     class="web-view" 
     col="0" 
     id="wv" 
     row="0" 
    ></WebView> 
</GridLayout> 

该文件使用一些图片,一些JS和一些CSS。

它在Android上正常工作,但我无法使它在iOS上工作。哦,它在iOS模拟器上工作正常,但不是在实际的设备中(我目前有用于测试这些东西的iOS 9 iPod touch)。

我在Info.plist上配置了正确的密钥(它与URL一起工作为https://www.google.com),我想我没有做任何奇怪的事情。

这是我的package.json

{ 
    "description": "WebView App", 
    "license": "LicenseRef-LICENSE", 
    "readme": "README", 
    "nativescript": { 
    "id": "com.app.name" 
    }, 
    "dependencies": { 
    "@angular/animations": "~4.1.0", 
    "@angular/common": "~4.1.0", 
    "@angular/compiler": "~4.1.0", 
    "@angular/core": "~4.1.0", 
    "@angular/forms": "~4.1.0", 
    "@angular/http": "~4.1.0", 
    "@angular/platform-browser": "~4.1.0", 
    "@angular/router": "~4.1.0", 
    "nativescript-angular": "~3.0.0", 
    "nativescript-theme-core": "~1.0.2", 
    "reflect-metadata": "~0.1.8", 
    "rxjs": "~5.3.0", 
    "tns-core-modules": "^3.0.1", 
    "zone.js": "~0.8.2" 
    }, 
    "devDependencies": { 
    "@angular/compiler-cli": "~4.1.0", 
    "babel-traverse": "6.24.1", 
    "babel-types": "6.24.1", 
    "babylon": "6.17.1", 
    "copy-webpack-plugin": "~4.0.1", 
    "lazy": "1.0.11", 
    "nativescript-css-loader": "~0.26.0", 
    "nativescript-dev-typescript": "~0.4.0", 
    "raw-loader": "~0.5.1", 
    "resolve-url-loader": "~2.0.2", 
    "tns-platform-declarations": "^3.0.0-rc.2", 
    "typescript": "~2.2.1" 
    } 
} 

回答

1

这对本地的网页一个已知的错误,它并不能够确定什么〜意味着在文件系统 而言,你需要的改变src在你的代码,并找出什么〜指的是。

使用:

import * as fs from "tns-core-modules/file-system"; 
public webViewSRC: string = encodeURI(`${fs.knownFolders.currentApp().path}/www/index.html`); 

看到这个问题:

https://github.com/NativeScript/NativeScript/issues/4443