EddyVerbruggen / nativescript-plugin-firebase

:fire: NativeScript plugin for Firebase
https://firebase.google.com
MIT License
1.01k stars 448 forks source link

Unable to retrieve iOS APNs Token using external_push_client_only #1723

Closed acutedeveloper closed 3 years ago

acutedeveloper commented 3 years ago

As the title suggests, I am using the Firebase plugin to provide a APNs token that I am sending to a external push notification provider.

I use the plug inside of a big project. Initially it was providing me with a APNs token via the firebase plugin. I recently made updates to NS CLI 7 & NS 7 and this is where the pain began!! I was not getting anywhere so I made a small repo to try and see what I was missing, but even here I am not successful. If I had a penny for time I ran ns clean today! My Repo is linked below:

github.com - Get iOS Token

I have followed the guides from here: configure-push-notifications-in-infoplist

With this basic setup

//--- app.ts
import { Application } from "@nativescript/core";

require("@nativescript/firebase");

Application.run({ moduleName: "app-root" });

//--- main-page.ts

import { messaging } from "@nativescript/firebase/messaging";

messaging
    .registerForPushNotifications({
        onPushTokenReceivedCallback: (token: string): void => {
            console.log("Firebase plugin received a push token: " + token);
        },

        onMessageReceivedCallback: (message) => {
            console.log("Push message received: " + message.title);
        },

        // Whether you want this plugin to automatically display the notifications or just notify the callback. Currently used on iOS only. Default true.
        showNotifications: true,

        // Whether you want this plugin to always handle the notifications when the app is in foreground. Currently used on iOS only. Default false.
        showNotificationsWhenInForeground: true,
    })
    .then(() => {
        console.log("Registered for push");
        messaging
            .getCurrentPushToken()
            .then((token) => console.log(`Current push token: ${token}`));
    });

The console results are

CONSOLE LOG: Registered for push
CONSOLE LOG: Current push token: undefined

onPushTokenReceivedCallback does not appear to be called!

I have tried to follow these issues for light:

FCM token is in a wrong format for iOS

Not receiving device token

Adding "messaging": true, to the firebase config provides me with a FCM token.

I believe that I have followed all I should, but I am clearly missing something! @EddyVerbruggen If your expert eye spots anything obvious, I would be very grateful for assistance.

Thanks in advance all.

henrychavez commented 3 years ago

Hi @acutedeveloper , I finally got the token, you need to set "messaging": false and test your app in a real device, because with the simulator the onPushTokenReceivedCallback is never called and the getCurrentPushToken returns undefined

acutedeveloper commented 3 years ago

Thanks for the feedback @henrychavez. You are indeed correct. I managed to get this resolved