为什么在使用ionic 3 cordova本机插件的verifyPhoneNumber方法时没有收到OTP SMS?

时间:2018-07-18 14:44:06

标签: android cordova ionic-framework ionic3 ionic-native

我正在使用https://github.com/arnesson/cordova-plugin-firebase来实现Firebase电话身份验证。

当我调用verifyPhoneNumber()...时,它将为我提供验证ID。

代码示例:

this.firebase.verifyPhoneNumber(phoneNumber,60)
    .then(
        function (verificationId) {
            console.log(verificationId)
            return verificationId;
        }
    )

控制台输出:

Object {
    instantVerification: false, 
    verificationId:  "here verification id"
}

但是,它没有将代码发送到给定的电话号码。

有什么帮助吗?

1 个答案:

答案 0 :(得分:0)

正如我在文档中看到的那样,他们说您需要先使用凭据登录,然后再发送SMS。也许您在示例代码之前执行此操作,否则,请使用此代码代替您的代码:

window.FirebasePlugin.verifyPhoneNumber(number, timeOutDuration, function(credential) {
    console.log(credential);

    // ask user to input verificationCode:
    var code = inputField.value.toString();

    var verificationId = credential.verificationId;

    var credential = firebase.auth.PhoneAuthProvider.credential(verificationId, code);

    // sign in with the credential
    firebase.auth().signInWithCredential(credential);

    // call if credential.instantVerification was true (android only)
    firebase.auth().signInWithCustomToken(customTokenFromYourServer);

    // OR link to an account
    firebase.auth().currentUser.linkWithCredential(credential)
}, function(error) {
    console.error(error);
});