我有一个离子应用程序,在其中我使用使用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环境中运行'
这就是我解决的问题“'RECAPTCHA只能在HTTP / HTTPS环境中运行”的问题。
进行平台检查:检查其iOS。
if (this.plt.is('ios')) {
//ios code here
} else {
//android here
}
现在添加以下代码(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.
});
}
现在创建令牌以使用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.
});
}
您必须添加反向的客户机ID,而不是普通的客户机ID。
这是我解决的方法。