ios - Nativescript + iOS webview + 本地文件

标签 ios webview nativescript local-files

我目前正在开发一个简单的应用程序,它有一个使用 WebView 的 HTML 部分。

内容在 app/www 文件夹中,我从“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 上配置了正确的 key (它与 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"
  }
}

最佳答案

这是本地页面的一个已知错误,它无法确定 ~ 在文件系统方面的含义 您需要更改代码中的 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

关于ios - Nativescript + iOS webview + 本地文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44505825/

相关文章:

objective-c - 有没有办法使用数学符号?

iOS - 多部分/表单数据发布

android - WebView.loadUrl(url,headers)在android中不起作用

nativescript - 在 NativeScript 布局中居中和右/左对齐项目

javascript - 使用 iframe 在 Nativescript Webview 中上传文件

ios - 如何使用最新的 FBSDK 在 iOS 应用程序中集成 Facebook 而无需重定向 Safari 浏览器

ios - plist文件中的NSArray或NSDictionary

javascript - Android webview位置检测javascript

javascript - Android与JavaScript、JS如何获取webview JS返回数据?

vue.js - 在 nativescript-vue 应用程序中哪里安装 axios?