Comments (39)
shouldnt some of this be in the documentation ? it ended up working for me but its fairly non trivial to understand that you need a specific message format to get a notification displayed and clicked with the app closed to trigger onNotification
from react-native-push-notification.
Hey @kfiroo @amrdraz I've no idea why now is working :|
This is what I did, I was using firebase endpoint (not working), then I changed to test using the code of @amrdraz (using GCM endpoint), start working, rollback and test again with firebase endpoint, works... :/
Is possible that switching between endpoint could fix something behind scenes?
Another note is that data
nested inside data
is not required, the next request works on both (GCM, FCM):
curl -X POST -H "Authorization: key=<MY_KEY>" -H "Content-Type: application/json" -d '
{
"data": {
"title": "Hello there",
"message": "some message text",
},
"to" : "<DEVICE_TOKEN>"
}' 'https://fcm.googleapis.com/fcm/send'
And from React native:
module.exports = React.createClass({
componentWillMount() {
PushNotification.configure({
// popInitialNotification: true,
onNotification: (notification) => {
console.log(notification)
}
})
}
})
Thank's guys for the help!
from react-native-push-notification.
Sending a notification with only the "data" field set (remove the "notification" field) works. Clicking on a notification triggers onNotification
once the app opens. It also gets triggered if the app is in the foreground.
from react-native-push-notification.
If you are overriding onNewIntent in MainActivity.java
and you do not call super on onNewIntent then that may be preventing onNotification from firing.
This could happen if you were to, say, use react-native-branch-deep-linking and follow their setup instructions you would override onNewIntent like this
@Override
public void onNewIntent(Intent intent) {
setIntent(intent);
}
A possible fix to get onNotification to fire is to add super.onNewIntent(intent):
@Override
public void onNewIntent(Intent intent) {
setIntent(intent);
super.onNewIntent(intent)
}
from react-native-push-notification.
UPDATE: It seems that onNotification is called after all when opening the app from the notification, but for some reason the YellowBox was not appearing when calling console.warn()
. Alert.alert()
does the trick though.
from react-native-push-notification.
After some debugging it looks like the onMessageReceived
method from the RNPushNotificationListenerService
class gets called when receiving the notification while the app is closed/in the background. But clicking on the notification itself only launches the app and does not pass its data to React.
@zo0r : any ideas on this? iOS working fine with clicking on notifications.
from react-native-push-notification.
@frangeris When I think about it I had some trouble finding the right structure of the notification I send from my server, that might be your problem!
my GCM payload looks like this:
JSON.stringify({
data: {
message: 'some message text',
sound: 'default',
// custom data goes here
data: JSON.stringify({
key: 'value'
})
}
})
from react-native-push-notification.
I'm having this same issue. I'm using node-gcm to send the notification to the app.
from react-native-push-notification.
Same here. Some help on how to overcome this issue would be great.
from react-native-push-notification.
@eduardb even when your application is completely closed?
from react-native-push-notification.
Completely, as in swiped away from the recents screen, yes.
from react-native-push-notification.
Awesome, i couldn't achieve that. Would you be so kind to share some
example on how to make it work?
On Wed, May 25, 2016 at 1:43 PM, Eduard Bolos [email protected]
wrote:
Completely, as in swiped away from the recents screen, yes.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#72 (comment)
from react-native-push-notification.
Have a look over this PR: novoda/spikes#57
from react-native-push-notification.
@eduardb how exactly do you have the Alert firing? I have an alert on the first line in onNotification, and it's working fine when the app is closed for iOS, but for Android it's not triggering.
from react-native-push-notification.
if revert this commit, It work?
from react-native-push-notification.
I don't know if its related but I never get onNotification
, weather the app is in the foreground or background.
from react-native-push-notification.
@npomfret https://github.com/rskull/react-native-push-notification
I was solved with this repository.
from react-native-push-notification.
Hey all,
I think I'm having a similar issue,
When the app is closed (swiped from recent on android and swiped up in iOS) and I receive a notification, it is displayed properly by the OS but when I click it the popInitialNotification
callback returns wrong data.
In iOS I receive:
{foreground:false}
In Android I receive:
null
Other then that everything seems to work perfectly!
Any idea what is going on?
Thanks,
kfir
from react-native-push-notification.
I'm facing the same issue, the approach of @eduardb is not working for me, nothing is triggered when the app is entirely closed, I tried using the Alert
, but nothing call onNotification
method.
@florindobre Could you please provide a simple example snippet of you test?
Sending a notification with only the "data" field set (remove the "notification" field) works
How can we solve this?
from react-native-push-notification.
@frangeris This pull request was supposed to resolve this issue 137
Not sure @zo0r published a new version yet but you can checkout this version and see if that works for you
from react-native-push-notification.
@kfiroo Thanks for the info.
Not sure if I'm correct, Am I missing something?
module.exports = React.createClass({
componentWillMount() {
PushNotification.configure({
popInitialNotification: (notification) => {
// when app is entirely closed and click on push notification
console.log('received', notification)
},
onNotification: (notification) => {
// ...
}
})
// ...
}
})
from react-native-push-notification.
@frangeris Looks like you might have misread the docs
When calling PushNotification.configure
the popInitialNotification
field is a boolean flag indicating whether to pop the initial notification or not, if true, it will try to pop the notification then normalize it and call the onNotification
function you passed to the configure
.
Hope that makes sense to you :)
from react-native-push-notification.
@kfiroo Thanks for the aclaration, about the value of the property as function instead of boolean, I was just testing a different approach, because neither of both is working for me, but ok using true (default) still not working.
Thanks
from react-native-push-notification.
@frangeris I think we need more information to be able to help you, like:
- Android / iOS?
- Are you using the latest code for this library?
- Is the app closed or in the background?
- Do you receive the notification in your phone at all?
from react-native-push-notification.
- Android 4.2.2
2.0.1
- Closed
- Yep, everything is working fine, except when app is entirely closed
Thanks
from react-native-push-notification.
@frangeris @kfiroo when the app is entirely closed (Android) the callback onNotification
is never called, its how RN
works (the bridge java->node->react
is dead at this point), the onNotification
will be called when the user tap the notification again.
from react-native-push-notification.
@zo0r then how do we trigger the notification message when the app is closed, or is this not possible?
from react-native-push-notification.
Thanks @zo0r, valuable information!
What would you suggest for approach this?
from react-native-push-notification.
@frangeris @amrdraz its not possible for now (2.0.1), I think a way to capture and execute the callback is re-open the activity in background (open and moveTaskToBack?) (if dead) and then execute onNotification
again.
As its not an user-intended behavior, (I think) sending the 'forcesReactNativeDelivery': bool
prop in the push data to re-open (if dead) the activity and execute the onNotification
callback.
Note that forcesReactNativeDelivery thing is not implemented yet, just a suggestion.
from react-native-push-notification.
@zo0r @amrdraz @frangeris Actually my PR made it possible, I'm using it in my app on production.
If I understand it correctly, this is the case in every Android app, the app is closed so you cannot handle the initial notification right away.
This is why the notification data is stored on an Intent
that is available on the Activity
.
In RNPushNotificationHelper.java#L213 we create a PendingIntent
that wraps the notification Intent
and later when the app starts and the JS code calls popInitialNotification
this code in
RNPushNotification.getInitialNotification we get the current Activity
from it we get the Intent
which holds the notification
data which we return to the client.
What do you think?
from react-native-push-notification.
@kfiroo you're right, but as I understand what @frangeris want is theonNotification
trigger immediately after the notification is received even if the app is closed.
@frangeris Am I right?
from react-native-push-notification.
Not exactly that case, this is the perfect scenario:
- App is entirely closed
- Push notification on phone
- User click on that notification
- Receive that data in
onNotification
If I could get onNotification
when user click on notification when the app is closed, that will be fine...
That's what I can't get @kfiroo, could you provide an example snippet please?
from react-native-push-notification.
@kfiroo I confirm that when I sent myself a push notification with the correct format it worked
from react-native-push-notification.
so the problem is that I test push notifications using this script
curl -X POST -H "Authorization: key=MYAPIKEY" -H "Content-Type: application/json" -d '
{
"data": {
"Title": "Hello there",
"Breif": "I got this"
},
"to" : "REGISTRATIONID"
}' 'https://gcm-http.googleapis.com/gcm/send'
changed it to
curl -X POST -H "Authorization: key=MYAPIKEY" -H "Content-Type: application/json" -d '
{
"data": {
"title": "Hello there",
"message": "some message text",
"data": {
"Title": "Hello there",
"Breif": "I got this"
}
},
"to" : "REGISTRATIONID"
}' 'https://gcm-http.googleapis.com/gcm/send'
@kfiroo @zo0r
Do you believe there should be a more flexible way of not conforming to a certain format?
and the second question is what are the available options? do I get to pass all the other otpions available to me in the localNotification method?
Either way this is enough for now thank you for your time
@frangeris I hope this solves your problem as well
from react-native-push-notification.
@amrdraz I'm using Firebase Cloud Messaging, so checking docs...
Thanks @kfiroo
from react-native-push-notification.
@amrdraz Great to hear that!
We could probably tweak the code to be less strict regarding the remote notification format, but I'm not an Android or iOS developer so I can't say if there is a standard that we should conform to.
Currently, as I can see from the code, the only restrictions are that the top level object will have a data
field and that inside this data
object we need a message
fields and it has to be a string.
Here we look for the data field on the root object - RNPushNotificationListenerService.java#L18 - not sure it's mandatory.
Here we simply return if we have no message
field - RNPushNotificationHelper.java#L92
from react-native-push-notification.
@frangeris Great to hear :)
Good luck
from react-native-push-notification.
@zo0r I think we can close this
from react-native-push-notification.
Yep, go ahead...
from react-native-push-notification.
Related Issues (20)
- reanimated - no version-specific reanimated AAR for react-native version 72 found
- Getting error when building project HOT 2
- Pushnotification listener not working while using multiple services ( OneSignal and react-native-push-notification) HOT 1
- React Native Firebase Push notifications for android build are not working for all the devices (In Android, have not tried in iOS yet) HOT 4
- Clicking on the android notification does not bring up the app HOT 1
- Missing permission android.permission.BROADCAST_CLOSE_SYSTEM_DIALOGS HOT 5
- Unable to start receiver com.dieam.reactnativepushnotification.modules.RNPushNotificationActions: java.lang.SecurityException: Permission Denial: android.intent.action.CLOSE_SYSTEM_DIALOGS broadcast from com.package.name requires android.permission.BROADCAST_CLOSE_SYSTEM_DIALOGS. HOT 2
- Scheduled notification is not coming android
- wrong sound when update version of app
- Foreground onNotification behaviour on iOS HOT 2
- Why are people still using this outdated library? HOT 3
- Indirect notification activity start (trampoline) from com.xxx blocked HOT 1
- How to pass and get data when notification clicked from .onNotification()
- -
- delete
- update build gradle version
- Scheduled Notifications are not displaying..... HOT 1
- Schedule Daily Notification is not working after few days if i did not open the app
- Android - Push notifications not received when app is closed (Killed/Terminated/etc) HOT 5
- Get onNotification triggered when a remote notification is received HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-push-notification.