20.9 C
New York
Friday, September 20, 2024

ios – verifyPhoneNumber in Flutter/Firebase app not working (‘token mismatch’)


I have been making an attempt to get ‘signinwithphonenumber’ working for DAYS now, however I simply cannot appear to do it on iOS. It works advantageous on Android, however strive as I would, I can not get the iOS model to work.

That is how I sign-in to firebase:

Future important() async {
  WidgetsFlutterBinding.ensureInitialized();

  // Initialize Firebase
  await Firebase.initializeApp(
    identify: '',
    choices: DefaultFirebaseOptions.currentPlatform,
  ).then((_) {
    print("Firebase initialized efficiently.");
  }).catchError((error) {
    print("Error initializing Firebase: $error");
  });

// Clear Firestore persistence right here
  strive {
    await FirebaseFirestore.occasion.clearPersistence();
    print('Firestore persistence cleared.');
  } catch (e) {
    print('Error clearing Firestore persistence: $e');
  }

  // Set Firestore settings
  strive {
    FirebaseFirestore.occasion.settings = const Settings(
      persistenceEnabled: false,
      sslEnabled: false,
      cacheSizeBytes: Settings.CACHE_SIZE_UNLIMITED,
    );
    print('Firestore settings up to date.');
  } catch (e) {
    print('Error organising Firestore: $e');
  }

  globals.fbdb = FirebaseFirestore.occasion;
  globals.fbauth = FirebaseAuth.occasion;
  globals.fbs = FirebaseStorage.occasion;

  // Run the app
  runApp(const ());
}

That is the place I attempt to confirm the cellphone quantity:

  static Future verifyPhoneNumber(String phoneNumber) async {
    await FirebaseMessaging.occasion.getToken();

    print("+++ phoneNumber = ${phoneNumber}");
    await globals.fbauth.verifyPhoneNumber(
      phoneNumber: phoneNumber,
      verificationCompleted: (PhoneAuthCredential credential) async {
        // Auto-retrieve verification code
        print("Verification Full has been triggered for some motive!");
      },
      verificationFailed: (FirebaseAuthException e) {
        // Verification failed
        print('+++ Verification failed. Error = ${e}');
      },
      codeSent: (String verificationId, int? resendToken) async {
        // Save the verification ID for future use
        print('acquired by means of to codeSent part');
      },
      codeAutoRetrievalTimeout: (String verificationId) {},
      timeout: Length(seconds: 60),
    );
  }
}

And this all the time triggers the ‘verificationFailed’ part, with the error ‘Token mismatch’.

That is the AppDelegate.swift:

import UIKit
import Firebase
import Flutter
import FirebaseMessaging
import FirebaseAuth

@important
@objc class AppDelegate: FlutterAppDelegate {
    override func software(
        _ software: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {
        // Firebase initialization
        GeneratedPluginRegistrant.register(with: self)
        Messaging.messaging().delegate = self
        return tremendous.software(software, didFinishLaunchingWithOptions: launchOptions)
    }

    override func software(_ software: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        if Auth.auth().canHandleNotification(userInfo) {
            print(userInfo)
            return
        }
        completionHandler(.newData)
    }

    override func software(_ software: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Information) {
        Auth.auth().setAPNSToken(deviceToken, sort: AuthAPNSTokenType.unknown)
    }
}

extension AppDelegate: MessagingDelegate {
    func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
        print("Firebase registration token: (String(describing: fcmToken))")
    }
}

Flutter model = 3.24.3 <> Steady channel
Dart 3.5.3
Devtools 2.37.3

Xcode: Model 15.4 (15F31d)

Android Studio Koala Characteristic Drop | 2024.1.2

Mac mini M2 Professional – 32GB

Testing on an iPhone 13 (actual gadget)

  • There aren’t any compile points
  • All of the plugins are updated (all of the Firebase ones are the most recent variations out there)
  • The ‘firebase-options.dart’ file is about up and proper (checked)
  • The URL Sort with the REVERSE_CLIENT_ID is right
  • I’ve checked and double checked all of the certificates from Apple, and the .p8 key has been re-generated about 4 occasions now simply to make sure I wasn’t having some type of blackout (!) once I was producing it or one thing
  • ‘Authentication’ on the Firebase console is about up with ‘Check in with Google’, ‘Signal In with cellphone quantity’ and ‘check in with e mail tackle and password’ – all of that are enabled.
  • The bundle names are all right, as is the identify of the Firebase app in every single place it is referenced
  • I’ve switched the ‘Autogenerated Key for iOS’ in Google Cloud Platform to being locked to iOS purposes
  • I am a paid Apple Developer
  • The best provisioning profile is about up
  • The GoogleService-Information.plist is in the suitable place and all of the content material is right
  • The Background modes within the ‘signing & capabilities’ part are set to ‘Background Fetch’ and ‘Distant Notifications’

That is from hours upon hours of scouring StackOverflow, studying and re-reading the documentation from Google, and doing the whole lot I can consider to get this to work…

…however all the identical code (precisely) works completely on Android.

HELP! I am shedding the desire to reside!

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles