首页 > 解决方案 > NativeScript loadStarted WebView 事件不会在 Android 上触发

问题描述

我在 NativeScript/Angular 中使用带有 loadStarted 和 loadFinished 事件的 Webview。在我的 iPhone (tns run ios) 上,这两个事件都被触发了。在我的 Android 手机(tns run android)上,未触发 loadStarted 事件,导致微调器发生故障。看起来只有与 tel:、mailto: 和 loc: 的链接触发 loadStarted 事件。希望有人可以帮忙。

XML:

<ActionBar #webviewActionbar title="Facilitor" flat="true">
    <ActionItem (tap)="onQrScanTap()" ios.position="right" ios.systemIcon="15" android.systemIcon="ic_menu_camera">
    </ActionItem>
</ActionBar>
<GridLayout rows="*">
    <WebView row="0" #loginView (loaded)="webviewLoaded($event);" (loadStarted)="webviewTrigger($event)" (loadFinished)="onLoadFinished($event)" (doubleTap)="onDoubleTap($event)" (swipe)="onSwipe($event)" [src]="webViewSrc" ></WebView>
    <TextField row="0" [(ngModel)]="registerModel.push_action" #pushActionModel="ngModel" autocorrect="false"
    autocapitalizationType="none" [visibility]="'collapse'" (textChange)="navigateToAction()"></TextField>
    <ActivityIndicator (loaded)="onSpinnerLoaded($event)" rowSpan="2" [busy]="isBusy" (busyChange)="onBusyChanged($event)" width="100" height="100"></ActivityIndicator>
</GridLayout>

打字稿:

  private onLoadFinished(args: any) {
    console.log("== onLoadFinished ==");
    this.isBusy = false;
  }
  private webviewTrigger(args: any) {
    console.log("== webviewTrigger ==");
    var webView: WebView = <WebView>args.object;
    console.log(webView);
    // get location
    if (args.url.startsWith('loc:')) {
      let arr = args.url.split(":");
      this.registerModel.push_action = this.registrationService.composeUrl() + arr[1] + "?longitude=" + this.lastLocation.longitude + "&latitude=" + this.lastLocation.latitude;
      this.navigateToAction();
      webView.reload();
      return;
    // handle mailto: and tel:
    } else if (args.url.startsWith('mailto:') || args.url.startsWith('tel:')) {
      utils.openUrl(args.url);
      webView.reload();
      return;
    }
    // start spinner
    this.isBusy = true;
  }

点击一些链接后的终端日志:

JS: == onNavigatingTo ==
chromium: [INFO:library_loader_hooks.cc(51)] Chromium logging enabled: level = 0, default verbosity = 0
JS: == webviewLoaded ==
JS: WebView(44)
JS: == setHTTPHeader ==
JS: == onSpinnerLoaded ==
JS: == onNavigatedTo ==
JS: == webviewTrigger ==
JS: WebView(44)
JS: indicator.busy changed to: true
JS: ===Location===
JS: == onLoadFinished ==
JS: indicator.busy changed to: false
JS: == onLoadFinished ==
JS: == onLoadFinished ==
JS: == onLoadFinished ==

标签: androidangularwebviewnativescript

解决方案


推荐阅读