larpon / QtFirebase

An effort to bring Google's Firebase C++ API to Qt + QML
MIT License
284 stars 83 forks source link

enable to retrieve token for messaging #45

Closed nero08 closed 6 years ago

nero08 commented 6 years ago

Hello,

I have a problem with Messeging plugin, the plugin is intialized and ready but it does not retrieve the token.

I put it in my manifest

https://pastebin.com/cywZHPUQ

my android ndk version is 14b

I've forgot something?

larpon commented 6 years ago

Can you please triple check if your setup is like the one in QtFirebaseExample? The messaging module works on my Android devices with the app produced from QtFirebaseExample. (maybe fetch the project and build it with Qt Creator to see if the error persists)

nero08 commented 6 years ago

I test and I receive notification but I can't retrieve the token, onTokenChanged is not emited and when I call messaging.token, the value is empty

larpon commented 6 years ago

Any progress? I get a token on all my 4 different test devices (real devices - not emulator)

nero08 commented 6 years ago

no, but I use a different solution, I call native code with QAndroidNative, my java file call firebase api who return the token. So it's ok

But in qml, I always don't retrieve the token, the onTokenChange is not emited

larpon commented 6 years ago

Hmm. I'll leave this open for the time being. Maybe other users will encounter the same problem

isipisi89 commented 6 years ago

Its workin on my devices fine too. Testet on iPhone 5, iPhone 5s, iPhone 6, Galaxy S6/S7/S8.

Furkanzmc commented 6 years ago

I've just investigated the code after deciding to use the library in my project, and it seems that the following signals are being connected too late.

connect(g_listener, &MessageListener::onMessageReceived, this, &QtFirebaseMessaging::getMessage);
    connect(g_listener, &MessageListener::onTokenReceived, this, &QtFirebaseMessaging::getToken);

before the componentComplete is called, the MessageListener receives the token and then calls onTokenReceived but there's no one to respond to that signal. The solution would be to connect the signals in constructor, and then check If there's a new token and then emit the tokenChanged signal in componentComplete.

larpon commented 6 years ago

@Furkanzmc - you might just be absolutely correct! I've had similar scenarios back when I started the project. It's worth a try. Nice catch! Do you happen to have a patch / PR for this?

driele-torres commented 6 years ago

@Furkanzmc Just yesterday, I noticed that! Then I saw your response, so I connected the signals in constructor and till now is working nicely! =D

larpon commented 6 years ago

Great news!

isipisi89 commented 6 years ago

@Furkanzmc https://github.com/Larpon/QtFirebase/commit/534a31455cf4bdba6d8127427dadd99a0df835b3 Should be fixed with this Update.