Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

With FirebaseAppDelegateProxyEnabled = false, phone authentication hangs and then crashes #231

Closed
dlcole opened this issue Aug 14, 2023 · 1 comment

Comments

@dlcole
Copy link
Contributor

dlcole commented Aug 14, 2023

This is related to the fix proposed in issue 221 regarding 'No APNS token specified error...

    <key>FirebaseAppDelegateProxyEnabled</key>
    <false/>

Adding the above lines to info.plist is sufficient to bypass the APNS error on iOS devices, but not iOS emulators.

BUT, this changes causes a hang in the login process. In particular,

let idp = await firebase().ui().show({ providers: [new PhoneProvider()] });

yields this sequence:

  1. Welcome screen presented, with "Sign in with phone" button as only visible option - tap button
  2. Enter phone number screen presented - enter number and tap Verify
  3. Verifying you’re not a robot… screen appears briefly
  4. about:blank screen appears, empty screen with Done (upper-left) and refresh (upper-right) as only options, and tapping Done cancels the login with an error, The interaction was cancelled by the user, and crashes
  5. When I attempt to display the error message with an alert, the still app crashes, even within a try/catch block
  6. When I attempt to log in again, ui().show crashes with the error message, Error: Cannot read properties of undefined (reading 'presentViewControllerAnimatedCompletion')

Might some type of Firebase AppDelegate be required for phone authentication?

image

@dlcole
Copy link
Contributor Author

dlcole commented Aug 14, 2023

I have found through my investigation that is sufficient to call getAPNSToken() prior to calling getToken() to avoid the dreaded error message

Error: The operation couldn’t be completed. No APNS token specified before fetching FCM Token

Doing so also avoids their hang/crash problem documented in this issue, so I will close it. You'll still want to catch the error, as it will be thrown on iOS emulators. My code, in app-root.js, looks like this:

try {
   const authStatus = await firebase().messaging().requestPermission({ ios: { alert: true, }, });
   const enabled = authStatus === AuthorizationStatus.AUTHORIZED || authStatus === AuthorizationStatus.PROVISIONAL;
   if (enabled) {
     await firebase().messaging().registerDeviceForRemoteMessages();
     firebase().messaging().showNotificationsWhenInForeground = false;

     const aPNSToken = firebase().messaging().getAPNSToken(); 
     const token = await firebase().messaging().getToken();
     global.deviceToken = token;
     // code to handle token... 

     firebase().messaging().onToken((token) => {
     // code to handle token
     });

      ...

} catch (e) {
   console.warn("app-root error: " + e);
 }

I have removed the lines from info.plist suggested by [issue 221](https://github.com/NativeScript/firebase/issues/221).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant