Currently React Native supports Push Notifications in iOS. Setting that up seems straightforward, however achieving the same functionality in Android seems much more challenging. Currently I don't see anything in the docs regarding setting up GCM (Google's push notification service) in React Native. The only module I have seen for GCM allows the service only on iOS. Is GCM on the roadmap for React Native Android?
cc @mkonicek
that said this should be pretty easy to set up yourself?
The Android Facebook Ads Manager uses push notifications. @foghina is the implementation battle tested and generic enough to open sourced?
As a side note, I think in general it's great if there are community modules for features like this at https://react.parts/native
Ideally if there are a few implementations, we can all learn from each other and come up with the best API over time.
The Ads Manager implementation is _not_ generic enough - it's tied with FB infra and pretty specific to Ads Manager itself.
The reason why this is a significantly harder problem on Android than on iOS is because Android gives you much more flexibility in dealing with push notifications. On iOS, when the server sends a push notification, _no application code is invoked in the app_, instead a notification is shown based on the payload and the app is invoked if/when the user taps on it.
On Android, the push notification actually triggers a BroadcastReceiver that is then responsible for reading the payload and deciding what to do with it. It can show a notification based strictly on the payload content or start a Service to make a network request to pull more info before showing one. Or, it can decide to ignore the push. Basically, you can run any code on a push.
This makes it hard because we want to have the business logic of handling a push in JS. This means running JS in a Service without a UI (so no ReactRootView...), ideally with a minimal / different / smaller bundle than the main app, for performance reasons (this is run while the device is awake _just_ to process push notifs, doing any extra work will result in your app using too much battery power).
In Ads Manager, the business logic is in Java, simply because we know what the payload is, how to create a UI notif from it and what Intent to launch when the user taps on it.
Furthermore, while iOS is (I think) tied to APNS for push delivery, on Android there are alternatives, e.g. Amazon Device Messaging. Ideally our APIs would be extensible enough to allow plugging alternative delivery methods.
@foghina thanks for the detailed overview! Really informative and actually reminds me a lot of iOS push notifications once you go past the super basic stuff. Same kinds of constraints like writing your notif handling in native so you don't have to spin up a JSContext :)
Wait, what do you mean by "notif handling"? Do you mean handling the user tapping on it or handling the push payload? IIRC the latter is not possible on iOS but maybe things have changed? I'm not very up-to-date on iOS dev.
Both under certain conditions. The specifics are a bit handwavy based on the APNS payload and various app entitlements but if you try all the combinations you can handle notifs without user interaction sometimes.
What was the direction here for push notifications on Android?
Hello, I am interested in react-native for android as well.
No ETA yet but we should eventually have support for push notifs on Android. Please post / vote here so we know how to prioritize: https://productpains.com/product/react-native/?tab=top
I'm currently working on open sourcing internal modules and view managers. Push notifications will require a bit more work because as Felix said this will need to be a different implementation from what we use internally.
You can try my module https://github.com/oney/react-native-gcm-android
@oney Cool! :+1:
@oney Can I use it in production?
@mkonicek Have you tested it?
Thanks !
@samuelcastro To be honest, I am not very professional with Android. I am more familiar with iOS. So maybe this module has some bugs and it isn't tested in all circumstances.
can anyone here good with Android fix the Contacts plugin by @rt2zz?
On Nov 22, 2015 9:58 PM, "Howard Yang" [email protected] wrote:
@samuelcastro https://github.com/samuelcastro To be honest, I am not
very professional with Android. I am more familiar with iOS. So maybe this
module has some bugs and it isn't tested in all circumstances.—
Reply to this email directly or view it on GitHub
https://github.com/facebook/react-native/issues/3423#issuecomment-158839064
.
so currently no push notification for Android in RN and no ETA?
+1
+1
There's a lot of RN apps, presumably some of them are using push notifications. Anyone know whether there's an open source alternative to use until it gets into RN core? I've been looking around and can't find anything. I just want the ability to have a server-side notification about an event that, when tapped, takes the user back to the app.
@pickhardt found anything usable? Looking for same
any updates? really look forward to PushNotification for Android
i got it work with https://github.com/oney/react-native-gcm-android react native v 0.20 connectd issue: #3683
Hi there! This issue is being closed because it has been inactive for a while.
But don't worry, it will live on with ProductPains! Check out its new home: https://productpains.com/post/react-native/react-native-android-gcm-google-cloud-messaging-roadmap
ProductPains helps the community prioritize the most important issues thanks to its voting feature.
It is easy to use - just login with GitHub. GitHub issues have voting too, nevertheless
Product Pains has been very useful in highlighting the top bugs and feature requests:
https://productpains.com/product/react-native?tab=top
Also, if this issue is a bug, please consider sending a pull request with a fix.
We're a small team and rely on the community for bug fixes of issues that don't affect fb apps.
Hi dude, i have also find out one good example
Android Push Notifications using Google Cloud Messaging GCM - Android Example
If you are using zo0r's react-native-push-notifications for android push notifications then you should check this answer.
Most helpful comment
The Ads Manager implementation is _not_ generic enough - it's tied with FB infra and pretty specific to Ads Manager itself.
The reason why this is a significantly harder problem on Android than on iOS is because Android gives you much more flexibility in dealing with push notifications. On iOS, when the server sends a push notification, _no application code is invoked in the app_, instead a notification is shown based on the payload and the app is invoked if/when the user taps on it.
On Android, the push notification actually triggers a BroadcastReceiver that is then responsible for reading the payload and deciding what to do with it. It can show a notification based strictly on the payload content or start a Service to make a network request to pull more info before showing one. Or, it can decide to ignore the push. Basically, you can run any code on a push.
This makes it hard because we want to have the business logic of handling a push in JS. This means running JS in a Service without a UI (so no
ReactRootView...), ideally with a minimal / different / smaller bundle than the main app, for performance reasons (this is run while the device is awake _just_ to process push notifs, doing any extra work will result in your app using too much battery power).In Ads Manager, the business logic is in Java, simply because we know what the payload is, how to create a UI notif from it and what
Intentto launch when the user taps on it.Furthermore, while iOS is (I think) tied to APNS for push delivery, on Android there are alternatives, e.g. Amazon Device Messaging. Ideally our APIs would be extensible enough to allow plugging alternative delivery methods.