【发布时间】:2020-12-23 01:42:04
【问题描述】:
我开发了一个带有电话号码身份验证的安卓应用,当我将它发布到 Play 商店时,它不再工作了。
在调试版本中,我通过短信收到了一次代码,但它不再起作用了。
用这个电话号码可以,只是不能用我的真实号码作为测试
1 - 在仪表板上启用对手机的访问 2 - SHA-1 在项目中设置
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.google.gms:google-services:4.3.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
jcenter()
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'com.google.firebase:firebase-analytics:17.2.2'
implementation 'com.google.firebase:firebase-auth:19.3.2'
implementation 'androidx.multidex:multidex:2.0.0'
implementation 'com.android.support:multidex:1.0.3' //with support libraries
}
apply plugin: 'com.google.gms.google-services'
Future<void> verifyPhone() async {
final PhoneCodeSent smsOTPSent = (String verId, [int forceCodeResend]) {
print("smsOTPSent");
print(forceCodeResend);
print(verId);
this.verificationId = verId;
smsOTPDialog(context).then((value) {
print('sign in');
});
};
try {
await _auth.verifyPhoneNumber(
phoneNumber: "+55" + this.telController.text, // PHONE NUMBER TO SEND OTP
codeAutoRetrievalTimeout: (String verId) {
//Starts the phone number verification process for the given phone number.
//Either sends an SMS with a 6 digit code to the phone number specified, or sign's the user in and [verificationCompleted] is called.
this.verificationId = verId;
print("verId " + verId);
},
codeSent: smsOTPSent, // WHEN CODE SENT THEN WE OPEN DIALOG TO ENTER OTP.
timeout: const Duration(seconds: 20),
verificationCompleted: (AuthCredential phoneAuthCredential) {
print("verificationCompleted " + this.telController.text);
print(phoneAuthCredential);
},
verificationFailed: (AuthException exceptio) {
print("fail");
print('${exceptio.message}');
}).timeout(const Duration(seconds: 2));
} catch (e) {
handleError(e);
print(e.printStackTrace());
}
}
verificaLogado(){
print("chamou: verificaLogado()");
print(_auth.currentUser());
_auth.currentUser().then((user) {
if (user != null) {
Navigator.of(context).pop();
Navigator.of(context).pushReplacementNamed('/homepage');
}else{
print("não logado");
}
});
}
signIn() async {
try {
final AuthCredential credential = PhoneAuthProvider.getCredential(
verificationId: verificationId,
smsCode: smsOTP,
);
final FirebaseUser user = (await _auth.signInWithCredential(credential)).user;
final FirebaseUser currentUser = await _auth.currentUser().timeout(Duration(seconds: 5));
assert(user.uid == currentUser.uid);
_showDialog('Sucesso', 'Autenticado com o número de telefone ' + user.phoneNumber);
_setPhoneFCM(currentUser.uid, currentUser.phoneNumber);
Navigator.of(context).pop();
Navigator.of(context).pushReplacementNamed('/homepage');
} catch (e) {
handleError(e);
print(e.printStackTrace());
}
}
【问题讨论】:
-
我想我发现了这个问题,即使遵循所有指南并注册测试电话号码,由于某种原因,我的网络 IP 在 firebase 服务器上被阻止。当我尝试使用手机的 4G 网络时,它起作用了
标签: android firebase flutter authentication