I'm writing a project in React-Native for both iOS and Android, I want to send notification automatically when users just install app but don't login or sign-up after 3 days. I'm using firebase cloud data for the project. Is it possible to do that over coding or firebase?
Asked
Active
Viewed 1,576 times
0
-
Your question does not make enough sense. What kind of notification are you talking about? Sending some sort of analytics notification of the event, sending a push notification to the user? What research have you done on the subject already? StackOverflow is meant to be used after you have already tried, so show us what you tried that didnt work - even if that just means I looked for 'x' on the internet and couldn't find anything. – Doug Watkins Jul 31 '20 at 19:23
-
Because you used the push-notification tag, I'm guessing you want to target those specific users with a push notification. Is your app designed to be usable by people without signing in or creating an account? Either way, it is possible to do what you are asking, but I think you are unlikely to actually reach many people. Apps that ask for notifications on first open usually get denied permissions. I would suggest looking into another way of getting a message to people who meet these criteria, such as a local notification controlled entirely by the app. – Doug Watkins Jul 31 '20 at 19:25
-
I researched many topics about it. But most of solution are about sending notification when you login or when you're online in the app. But I want to send notification like "we miss you , or why don't you still login our app?" ,when users download app but not open it even one time. One of the solution about it is "You want to set an alarm that starts a short-running service once per day. All that service does is to check something like a shared preference for the last-used-time. If that time is more than 3 days old, then the service sends a notification. Either way, the service then exits. – Veysel Turan Aug 01 '20 at 13:56
-
"Alternatively, your app could submit an alarm, each time it runs, that is defined to fire in 3 days and defined to replace any pre-existing alarm with the same ID. That alarm would be defined to open a short-running service that sends a notification.(https://stackoverflow.com/questions/22709751/how-to-send-notification-if-user-inactive-for-3-days/22710380)" Is that solution possible in react-native. I have no idea how to set an alarm that starts a short-running service once per day. – Veysel Turan Aug 01 '20 at 13:56
1 Answers
3
Using Firebase, you can get the FCM token for the device even without them being logged in. You will needs to get their permission to receive notifications though.
import React, { Component } from "react";
import { Text, View } from "react-native";
import firebase from "react-native-firebase";
export default class componentName extends Component {
async componentDidMount() {
this.checkPermission();
}
//1
async checkPermission() {
firebase
.messaging()
.hasPermission()
.then((enabled) => {
if (enabled) {
this.getToken();
} else {
this.requestPermission();
}
});
}
//2
async requestPermission() {
firebase
.messaging()
.requestPermission()
.then(() => {
this.getToken();
})
.catch((error) => {});
}
//3
async getToken() {
fcmToken = await firebase.messaging().getToken();
if (fcmToken) {
//
//
//
//
//
// Call your API here
//
//
//
//
//
//
}
}
render() {
return (
<View>
<Text> Your APP </Text>
</View>
);
}
}
Evans Munene
- 101
- 5
-
1Thank you:) This solution may work. I'll try it and send you a feedback whether it works or not. – Veysel Turan Aug 01 '20 at 14:00