1

我有一个页面想要在单击按钮时启动外部应用程序并且函数 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'));
        }


}

4

1 回答 1

1

在向您的应用程序添加新模块时,您是否遵循了您需要执行的标准部分:

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

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

...

@NgModule({
  ...

  providers: [
    ...
    AppLauncher
    ...
  ]
  ...
})
export class AppModule { }
于 2019-07-02T03:45:38.397 回答