【问题标题】:How to call Capacitor plugin for Google Auth如何为 Google Auth 调用 Capacitor 插件
【发布时间】:2020-10-11 05:58:05
【问题描述】:

您好,我正在尝试在 Ionic 5 中使用社区电容器插件:-

https://github.com/CodetrixStudio/CapacitorGoogleAuth

我的 html 看起来像

</head>

<ion-header>
  <ion-toolbar color="secondary">
    <ion-title>
      Capacitor testy
    </ion-title>
  </ion-toolbar>
</ion-header>

<ion-content>
  <img [src]="image" *ngIf="image">
  <ion-button (click)="openBrowser()">Open Browser</ion-button>
  <ion-button (click)="takePicture()">Take Picture</ion-button>
  <ion-button (click)="glogin()">glogin</ion-button>
</ion-content>

还有我的 TS

import { Component } from '@angular/core';
import { Plugins, CameraResultType } from '@capacitor/core';
import { DomSanitizer } from '@angular/platform-browser';
const { Browser, Camera } = Plugins;
import '@codetrix-studio/capacitor-google-auth';



@Component({
  selector: 'app-home',
  templateUrl: 'home.page.html',
  styleUrls: ['home.page.scss'],
})
export class HomePage {
 image = null;
  constructor(private sanitizer: DomSanitizer) {}


  async openBrowser(){
  await Browser.open({ url: 'https://www.neilson.co.uk/beach/greece/cosmos-beachclub' });
}

  async takePicture() {
    const image = await Camera.getPhoto({
      quality: 90,
      allowEditing: true,
      resultType: CameraResultType.Uri
    });
    console.log('image: ', image)
    this.image = this.sanitizer.bypassSecurityTrustResourceUrl(image && image.webPath);
 }

 async glogin(){
  let auth = await Plugins.GoogleAuth.signIn();
  console.log('auth' + auth);
  }

  
}

但是 GoogleAuth.signIn();在 VS 代码中出现红色下划线 - 此处传递的含义是什么?

谢谢

【问题讨论】:

    标签: ionic-framework capacitor


    【解决方案1】:

    在Android studio中,找到文件android/app/src/main/java///MainActivity.java,将插件添加到初始化列表中:

    import com.codetrixstudio.capacitor.GoogleAuth.GoogleAuth
    this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{
    ...
    add(GoogleAuth.class);
    ...
    }});
    

    来源:https://enappd.com/blog/google-login-in-ionic-react-capacitor-apps/122/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-03-30
      • 1970-01-01
      • 2022-07-15
      • 2021-06-03
      • 2021-09-18
      • 1970-01-01
      • 2019-03-23
      相关资源
      最近更新 更多