在Ionic 4中启动外部应用程序的白屏

时间:2019-07-01 13:42:18

标签: ionic-framework ionic4 app-launcher

我有一个页面,当单击一个按钮并且函数goToApp()应该运行时,我想启动外部应用程序。

以下是我在ts文件上的代码,但是页面上的所有内容都可以加载到我添加的点为止

从“ @ ionic-native / app-launcher / ngx”导入{AppLauncher,AppLauncherOptions};

页面紧随其后不再加载。没有返回错误代码。任何想法?预先感谢。

import { Component,OnInit,Input } from '@angular/core';
import { AppLauncher, AppLauncherOptions } from '@ionic-native/app-launcher/ngx';
import { ModalController, Platform } from '@ionic/angular';
import { DomSanitizer,SafeResourceUrl } from '@angular/platform-browser';
/*
  Generated class for the Posts page.

  See http://ionicframework.com/docs/v2/components/#navigation for more info on
  Ionic pages and navigation.
*/

@Component({
  selector: 'page-fsfastcheck',
  templateUrl: 'fsfastcheck.html',
  styleUrls: ['fsfastcheck.scss'],
})


export class FSFastCheckPage implements OnInit {
  @Input()
  url: string = "https://eastchenconsultancy.com/feng-shui-fast-check/";
  url2: string = "https://eastchenconsultancy.com/appointment-list/";
  urlSafe: SafeResourceUrl;
  urlSafe2: SafeResourceUrl;
  mySegment: string = 'travelrequest';

  constructor(
      public modalView: ModalController,
      public sanitizer: DomSanitizer,
      private appLauncher: AppLauncher, private platform: Platform) { }

      ngOnInit() {
        this.urlSafe= this.sanitizer.bypassSecurityTrustResourceUrl(this.url);
        this.urlSafe2= this.sanitizer.bypassSecurityTrustResourceUrl(this.url2);
      }

      close() {
        this.modalView.dismiss();
      }

      goToApp() {
        const options: AppLauncherOptions = { }

        if(this.platform.is('ios')) {
          options.packageName = 'com.apple.compass'
        } else {
          options.packageName = 'com.gn.android.compass'
        }

        this.appLauncher.canLaunch(options)
          .then((canLaunch: boolean) => console.log('Compass is available'))
          .catch((error: any) => console.error('Compass is not available'));
        }


}

1 个答案:

答案 0 :(得分:1)

您已遵循将新模块添加到应用程序时需要执行的标准步骤:

基本上,您需要将模块注入应用程序:

// app.module.ts
import { AppLauncher } from '@ionic-native/app-launcher/ngx';

...

@NgModule({
  ...

  providers: [
    ...
    AppLauncher
    ...
  ]
  ...
})
export class AppModule { }