简体   繁体   English

Nativescript + iOS webview +本地文件

[英]Nativescript + iOS webview + local files

I'm currently working in a simple app, which has a HTML section which uses a webview. 我目前正在使用一个简单的应用程序,它有一个使用webview的HTML部分。

The contents are in an app/www folder, and I access them from a "home.ts" component with something like this in the HTML 内容位于app / www文件夹中,我从HTML中的“home.ts”组件访问它们

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

This file uses a few images, some JS and some CSS. 这个文件使用了一些图像,一些JS和一些CSS。

It works fine on Android, but I can't make it work on iOS. 它在Android上运行良好,但我无法在iOS上运行。 Oh, and it works fine on the iOS emulator, but not in an actual device (I currently have a iOS 9 iPod touch for testing these things). 哦,它在iOS模拟器上工作正常,但在实际设备中没有(我目前有一个用于测试这些东西的iOS 9 iPod touch)。

I have the correct keys configured on Info.plist (it works with URLs as https://www.google.com ), and I think I'm not doing anything weird. 我在Info.plist上配置了正确的密钥(它使用URL作为https://www.google.com ),我想我没有做任何奇怪的事情。

This is my package.json 这是我的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"
  }
}

It's a known bug for local pages, it's not able to determine what ~ means in terms of filesystem you need to change the src in your code and figure out what ~refers to. 这是本地页面的一个已知错误,它无法确定在文件系统方面你需要更改代码中的src并找出〜所指的内容。

using : 使用:

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

See this issue : 看到这个问题:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM