I’m building a flutter app and have encountered a weird problem that I haven’t seen before. I’m using Firebase auth for phone verification through OTP.
However, I only receive OTPs on the debug mode for iOS and not the release mode. It works fine on Android in both cases. I’m not sure what I’m doing wrong as I have the updated GoogleService-info.plist in my iOS root. Do you guys have any ideas on how I can make it work?
This is my workflow when I verify the OTP:-
Future<void> verifyPhone(String phoneNumber, ) async {
await FirebaseAuth.instance.verifyPhoneNumber(
phoneNumber: phoneNumber,
timeout: const Duration(seconds: 60),
verificationCompleted: (PhoneAuthCredential credential) {
print('Auth completed');
},
verificationFailed: (FirebaseAuthException e) {
print(e);
print('Auth failed');
},
codeSent: (String verificationId, int? resendToken) {
print('OTP sent');
verId = verificationId;
Queries.instance.verId = verificationId;
print(verId + '........');
},
codeAutoRetrievalTimeout: (String verificationId) {
print('Timeout');
}
);
}
2
Answers
For some Firebase related functions to work in iOS, you will have to link your Firebase project with Apple Push Notification Service’s APN key.
Things you can do,
For reference,
https://www.kodeco.com/20201639-firebase-cloud-messaging-for-ios-push-notifications
Below-mentioned is my function for OTP verification:
You can cross-verify with your function to check the difference, or else if you want to full source code, it is available at:
https://github.com/dharambudh1/firebase-otp-integration-demo/