EddyVerbruggen / nativescript-plugin-firebase

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

[iOS] Push only usage not getting token #1227

Closed PeterStaev closed 5 years ago

PeterStaev commented 5 years ago

I have the following code:

    messaging.registerForPushNotifications({
        onMessageReceivedCallback: (message) => {
            console.log(message);
        },
        onPushTokenReceivedCallback: (token) => {
            console.log(token);
        }
    }).then(() => {
        console.log("Register Done!");
    });

Although this works fine on Android on iOS i'm not getting any token. Below is the log from when the app is deployed to iPhone X:

[inc.tangra.azuremobileservicessample] Requesting authorization with options 7
[inc.tangra.azuremobileservicessample] Setting badge number to 0
[inc.tangra.azuremobileservicessample] Setting badge number to 0
[inc.tangra.azuremobileservicessample] Requesting authorization with options 7
[inc.tangra.azuremobileservicessample] Set badge number [ hasCompletionHandler: 0 hasError: 0 ]
CONSOLE LOG file:///app/main-page.ts:175:0: Register Done!
[inc.tangra.azuremobileservicessample] Set badge number [ hasCompletionHandler: 0 hasError: 0 ]
[inc.tangra.azuremobileservicessample] Requested authorization [ didGrant: 1 hasError: 0 hasCompletionHandler: 1 ]
[inc.tangra.azuremobileservicessample] Requesting token for remote notifications
[inc.tangra.azuremobileservicessample] Requested authorization [ didGrant: 1 hasError: 0 hasCompletionHandler: 1 ]
[inc.tangra.azuremobileservicessample] Requesting token for remote notifications
[inc.tangra.azuremobileservicessample] Requested token for remote notifications [ didSucceed: 1 hasError: 0 hasCompletionHandler: 1 ]
[inc.tangra.azuremobileservicessample] Requested token for remote notifications [ didSucceed: 1 hasError: 0 hasCompletionHandler: 1 ]
[inc.tangra.azuremobileservicessample] Did receive remote notification token
[inc.tangra.azuremobileservicessample] Sending received device token to delegate UIApplication
[inc.tangra.azuremobileservicessample] Did receive remote notification token
[inc.tangra.azuremobileservicessample] Sending received device token to delegate UIApplication

If I try to get the token via messaging.getCurrentPushToken() the promise gets resolved with undefined.

I'm using the plugin in "push only" set up:

{
    "external_push_client_only": true,
    "using_ios": true,
    "using_android": true
}
PeterStaev commented 5 years ago

Problem was in my setup:

  1. I had to RFM and add the required settings in the Info.plist file like explained in the docs
  2. I had a custom Application Delegate that was overriding the settings this plugin does. So I just moved the register of my delegate before the require of the firebase and all works fine now.