fechanique / cordova-plugin-fcm

Google FCM Push Notifications Cordova Plugin
623 stars 995 forks source link

RefreshToken doesn't work #205

Open blackholegalaxy opened 7 years ago

blackholegalaxy commented 7 years ago

Hi there.

I tried to use both your old and new version of plugin and I encounter these errors.

On the < 2.0.0 version

We are then unable, at first app launch, to get a valid token on Android. We have to fully close the app before we can achieve obtaining a token.

Please note: in Emulator, it works at first launch. On real device no...

On the 2.0.0 version

The getoken method doesn't exist anymore. The onRefreshToken method exists BUT it's never called. So we don't obtain any token.

I tried to put the function in onDeviceReady part of cordova script but it doesn't do anything.

SO, we don't get any token. I tried then to use push notifications, but it never shows up. I tried to rebuild the app, try to even see, anywhere in the log, if we manage to get a token, but nothing. I also tried, of course, to close the app and rerun it. No success.

Bonus bug

It also appears your version is now incompatible with admob pro, there is a googleservices conflict of versions.

kapilrc commented 7 years ago

On the 2.0.0 version, FCMPlugin do not return any functions, and so app freezes. screenshot from 2017-01-16 14-50-01

psaussure commented 7 years ago

I get the same issue: the onRefreshTokenMethod is never triggered. So at first app launch on Android, no token is issued. If i fully close then reopen, it works. But it's not a correct behavior.

ghost commented 7 years ago

I do the same.

nickwinger commented 7 years ago

I have the same Problem, the callback is never called. Even on complete restart of the app it is not called. I never get any token no more (it has worked already). Any hints anyone please ?

tipstrade commented 7 years ago

Same issue - I'm slowly going up the call stack - so far I've got to onTokenRefresh() in MyFirebaseInstanceIDService.java - and am seeing none of the debug logging that I would expect to see.

All I can take from that is onTokenRefresh isn't being called in the extended FirebaseInstanceIdService class, which sounds vaguely familiar to Firebase onTokenRefresh() is not called on SO

onTokenRefresh in FirebaseInstanceIdService is only called when a new token is generated. If your app was previously installed and generated a token then onTokenRefresh would not be called. Try uninstalling and reinstalling the app to force the generation of a new token, this would cause onTokenRefresh to be called.

The problem is that the getToken method - which I used to use - has been removed from the plugin. I don't know why that was done. Maybe it's a case of adding a wrapper function back in

Edit: The getToken function still exists FCMPlugin.java, it's just the javascript entry point that appears to have been removed.

nickwinger commented 7 years ago

I also guess that the old getToken method is missing here, because the Plugin needs to call getToken at least once (to receive any existing token): This has to be called on Plugin-Start (or getToken as before) String token = FirebaseInstanceId.getInstance().getToken();

I'm looking into using javascript directly without the cordova-plugin-bridge: https://firebase.google.com/docs/cloud-messaging/js/client

nickwinger commented 7 years ago

This seems to be same cordova-plugin, but it still has the getToken method ?!? https://github.com/guyromb/cordova-plugin-fcm-plus

tipstrade commented 7 years ago

@nickwinger Yup, I just reverted the change made by 06dc209e39bf6149 that removed the getToken method. Rebuilt and lo and behold I can get the token back on demand.

I appreciate the method may return null - as some people have mentioned - that's something I'll be prepared to handle.

The main issue I see is that even when I removed my app and reinstalled it (killed it, re-ran), the callback passed to onTokenRefresh was never invoked, so it wasn't possible for me to get the token

As for guyromb's fork, I honestly don't know which plugin to use now - there are so many versions floating around. I guess I'll make do a use my forked version of this that fixes this (and also implements #175 by @jach145)

So, I'll link to yet another fork - mine - sigh... tipstrade@695ccc12bd02bd4c43a1ba92905893d4a11f3eee

nickwinger commented 7 years ago

@tipstrade How can we install your fork as a cordova plugin ? It is just on github right now ?

tipstrade commented 7 years ago

The repository has updated to include the getToken method (amongst other changes), and it looks like it's already on npmjs.

However, in the future if you need to use alternative forks/version, you can make the following changes: package.json

"cordovaPlugins": [
  /*"cordova-plugin-fcm", */
  {
      "locator": "https://github.com/tipstrade/cordova-plugin-fcm",
      "id": "cordova-plugin-fcm"
  }
]

config.xml

 <!-- <gap:plugin name="cordova-plugin-fcm" source="npm" />-->
  <gap:plugin name="cordova-plugin-fcm" source="git" spec="https://github.com/tipstrade/cordova-plugin-fcm" />