没有在iOS上重新配置的离子Firebase phoneAuth

问题描述 投票:0回答:1

我有一个离子应用程序,在其中我使用使用recaptcha的Firebase电话身份验证。它在android上运行良好,但在ios上引发错误,提示recaptcha只能在http环境中运行。我想知道是否可以在不使用Recaptcha的情况下执行Firebase电话身份验证。

    this.recaptchaVerifier = new firebase.auth.RecaptchaVerifier('recaptcha-container',{
      'size': 'invisible'
    });


              let appVerifier = this.recaptchaVerifier;
              this.appService.sendPhoneVerification(phoneNumber,appVerifier) 
              .then(confirmationResult => {
                   //do something
                })

ios抛出错误'RECAPTCHA只能在HTTP / HTTPS环境中运行'

firebase ionic4 recaptcha
1个回答
0
投票

这就是我解决的问题“'RECAPTCHA只能在HTTP / HTTPS环境中运行”的问题。

  1. 安装Firebase插件:plugin link
  2. 将其添加到您的app.module.ts。
  3. 进行平台检查:检查其iOS。

    if (this.plt.is('ios')) { //ios code here } else { //android here }

  4. 现在添加以下代码(iOS平台)以向用户发送验证码sms以验证电话号码。将插件注入构造函数。创建一个变量以分配诺言中的数据。电话号码应为国家代码+号码。例如'+19999999999'

    public signInUser(phoneNum) { this.firebase.verifyPhoneNumber(phoneNum).then((vdata) => { this.refConfirm = vdata; //you can redirect the person to a verification page or show an alert to input verification code. }); }

  5. 现在创建令牌以使用Firebase使用凭据验证和登录用户。

    public verifyPhoneNumber(phoneNumber) { let tokenPhone = firebase.auth.PhoneAuthProvider.credential(this.refConfirm, phoneNumber); firebase.auth().signInWithCredential(tokenPhone).then((verifiedData) => { //whatever you want to do here or redirect the user to home page. }); }

  6. 在Firebase上生成您的GoogleService.plist并添加到您的项目根目录enter image description here

  7. 您必须添加反向的客户机ID,而不是普通的客户机ID。

    enter image description here

  8. 这是我解决的方法。

© www.soinside.com 2019 - 2024. All rights reserved.