Nativescript + iOS webview + local files

I am currently working on a simple application that has an HTML section that uses webview.

The content is in the app / www folder and I am accessing them from the "home.ts" component with something like this in HTML

<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 multiple images, some JS and some CSS.

It works great on Android, but I cannot get it to work on iOS. Oh, and it works fine on the iOS emulator, but not on the device itself (I currently have an iPod touch for iOS 9 to test these things).

I have the correct keys configured on Info.plist (it works with urls like https://www.google.com ) and I think I'm not doing anything weird.

This is my .json package

{
  "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"
  }
}

      

+3


source to share


1 answer


This is a known bug for local pages, it cannot figure out what ~ means in terms of filesystem, you need to change src in your code and figure out what ~ means.

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

+1


source







All Articles