Someone know how can I cancel local push notifications when user is on a particular screen?
I'm using react-native-push-notification that should stop getting notifications when the user is in the chat screen and resume this action when he lives...
Try putting PushNotification.cancelAllLocalNotifications(); in the component's ComponentDidMount method.
As I understand you are trying to implement push notification sending only when the user's app is in background mode.
Why don't you just use offline push notifications for this case?
Many backend providers like ConnectyCube have this option. So, you just need to manage app states to handle background mode via AppState.currentState and make sure that the device is subscribed to pushes.
Or do you mean you need to send pushes when the user is in the app, but on another chat screen too?
Related
I am building an app like Messenger, everything works normally like sending messages, receiving messages, video calling. the technologies i use are react-native, reactJS, socket.io, nodeJS, react-native-webrtc
I wonder how can when I close an app like the messenger I can still receive incoming call notifications from other people. I'm studying firebase notification and react-native-background-timer but it doesn't seem to work the way I want it to
Has anyone had a problem like this and have an answer, please let me know
Have a nice day guys <3
In react native firebase there are two types of notifications "background" and "foreground".
Foreground Notifications:
A foreground service performs some operation that is noticeable to the user. For example, an audio app would use a foreground service to play an audio track. Foreground services must display a Notification. Foreground services continue running even when the user isn't interacting with the app.
When you use a foreground service, you must display a notification so that users are actively aware that the service is running. This notification cannot be dismissed unless the service is either stopped or removed from the foreground.
Background Notification:
A background service performs an operation that isn't directly noticed by the user. For example, if an app used a service to compact its storage, that would usually be a background service.
You want to follow there Documentation to apply push notifications in react native.
My app currently supports a chat function which is working only with Firebase Firestore, nothing else.
My idea is to implement a notification whenever a new message is received, the catch is: I want to get the notification even if the app is closed. (If you close Instagram or Whatsapp you also get notifications if somebody messages you, that's what I mean.)
The problem I face is that all Firebase listener work only as long as my app is connected to the Firebase servers but as soon as I close the app of course the app disconnects from the servers and so do the listeners not work anymore.
What I need is a function or a feature to track in the background if something on the Firebase Firestore has changed (in this case, if a new documents in a specific location was created) and if yes, trigger a notification, even if the app is closed.
Does anybody have an approach for me how I could accomplish this task?
You can use Firebase cloud messaging to solve this problem as whenever there is new data available to sync it checks with the client device status and updates it. Here you can find step by step guide on how to set it up.
I have a react native app and after Cloud function send any notification to users I save it in a real-time Database,
In the Home screen, I add a bell 🔔 when the user clicks it will navigate him to a specific screen contains all notifications saved to a real-time database( firebase ),
So my question is I want to add a counter if the user gets a new notification it will increase and after a click to the bell and navigate to notifications detail screen and get back to Home screen should be a 0 count or just a bell without a counter,
how can I do it?
My thought is I just add a listener in the home screen and just get the length of notification array after fetching from firebase and if any new notify to come to the length will increase and after navigating to notification screen I reset the notification array to be [ ] or something,
But in every single time, I open the app and go to "Home Screen" I will get the count "length of notifications array after fetched" .. so that's bad
So what you think?
A simple answer would be to store a count of what has been read locally in AsyncStorage and read that when the app starts.
Obviously it's a pretty limited solution on its own, e.g. it will be wrong if the user uses a different device, eventually the number will roll over, what happens when the notifications are purged from the DB.
As Firebase was mentioned, it may be worth having a look at what their Firebase Cloud Messaging or the Beta Firebase In-App Messaging service provides by means of help to implement something nicer. Also, if not found it already, the invertase/react-native-firebase collection seems to give access to most of Firebase's functionallity.
I wanted to add a push notification system on my web app.
Example:
one user is clicking on the button of one website. a second user is
notified about the click like a push notification
I tried a lot of things: Notification push with services workers but I am stuck when it is necessary to use his own server because there is only me who can be notified with my Key.
Please help!
One way I would recommend is to use OneSignal.
It has APIs and well written document. It is easy to get it to work too.
I'm trying to create a button action on a website that will send a notification alert on my phone (Kind of like a pager).
I have a button on a website, and I'm trying to determine what the best way to receive notification of that button press on my Android phone.
Basically:
Button Press on website -> Notification on phone saying button was pressed
How would I implement this in JavaScript, and what would be the best service to do so? Maybe through Google Push, or even another app that I can piggy back off of an existing IM service?
I imagine you can use 2 approaches:
Push Notifications
WebSockets
Both of them are workable solutions for your issue
Probably, Push Notifications will be easier and more resource-consuming for mobile app, so let me explain how you can do it
There are lot's of ready-to-go and FREE solutions for push notifications, for example, ConnectyCube
So the flow can be like this:
You have a user (you can create it via ConnectyCube dashboard, Users module). So you use this user on both Web and Android ends
On Android part, you authenticate this user and subscribe for push notifications
On web part, you also authenticate this user. Then send a push notifications for himself when a button was pressed
So Android user will receive a push then