我有一个离子应用程序,我使用 firebase 电话身份验证,该身份验证使用 recapcha。它在 android 上运行良好,但在 ios 上抛出错误,提示 recaptcha 只能在 http 环境中运行。我想知道是否有一种方法可以在不使用验证码的情况下执行 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 环境中运行”
嗯,这就是我解决问题“'RECAPTCHA 只能在 HTTP/HTTPS 环境中运行'”的方法。
- 安装 Firebase 插件:插件链接 https://ionicframework.com/docs/native/firebase
- 将其添加到您的 app.module.ts 中。
-
进行平台检查:检查是否为 iOS。
if (this.plt.is('ios')) {
//ios code here
} else {
//android here
}
-
现在添加以下代码(iOS平台)向用户发送验证码短信以验证电话号码。将插件注入到构造函数中。创建一个变量来分配 Promise 中的数据。电话号码应为国家代码+电话号码。例如“+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.
});
}
-
现在创建一个令牌来使用 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.
});
}
Generate your GoogleService.plist on Firebase & add to your project root directory![enter image description here](https://i.stack.imgur.com/KXUON.png)
-
您必须添加反向客户端 ID,而不是正常客户端 ID。
我就是这样解决的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)