-
-
Notifications
You must be signed in to change notification settings - Fork 83
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
How to connect to MessageReceived signal from C++? #71
Comments
You want to connect from outside? |
Yes |
If you can connect via QML it should indeed get the same results as when connecting in C++. But I'm not sure any Qt or related code will be triggered if your app is in the background. If it's not running I don't think your code will run per design. If your app is in the background you'll get a notification that open your app. If you're doing this from iOS please cruise issue #49 for a messy checklist of what should be ensured before messages come through |
If you want to receive a token from C++ you can connect to the tokenChanged signal just as you've done above, but since the signal doesn't emit the token value as a parameter, you'll need to have access to the QtFirebase instance from inside Notification::messageReceived, so you can call the token accessor. The messageReceived is emitted from QtFirebaseMessaging::setData, which currently only updates when the data has changed. This prevents you from sending more than one message with the same data at a time. In your case if you're trying to send the same message over and over, it will be per app run. Since I didn't want to break the QML API and didn't have a better alternative solution ready, my solution to this problem was to comment out the |
@adolby - I can see why you'd need to be able to send out the same message more than once in the same app run (although it might be user bombardment, if not for testing purposes). We could add a bool for the emit upon data received. Something like So we'd check: It also makes sense to pass the token to the signal as a parameter - it's useful - also from QML |
Yeah, the flag for always emitting would be helpful for me-- the use case is that the message is a command from a server to tell the app to synchronize data, which really doesn't need any more data then the command itself. It's also used for sending data only and not in messages shown to the user-- I agree that that would probably be bad to continue showing the same notification message to users. We could have just as easily added a timestamp to the message data to have avoided this issue, though, which might be a better way to have solved the problem. |
When not running from QML but straight from c++, you need to have the following line as well because this is where QtFirebaseMessaging does some of its own connections for messages and tokens: |
Hello. How can I receive message (and token) inside my application? For now I do like this:
auto firebase = QtFirebaseMessaging::instance(); Notification handler; QObject::connect(firebase, &QtFirebaseMessaging::messageReceived, &handler, &Notification::messageReceived);
Where Notification is my class. But I do not receive any signal. Also, no notification when App is opened.
The text was updated successfully, but these errors were encountered: