Closed shaikhussian closed 4 years ago
this is not work in Android
but worked is iOS
You are half right :) This doesn't work on Android when you're running a debug variant. But it DOES work if you run a release variant. Just tested it on Android, the 'onNotification' callback is being called with the notification data when you click the notification while the app is in the background/dead... Just run $ react-native run-android --variant=release to see for yourself.(Obviously you will not be able to debug it.. So show a toast from the callback or something)
release variant is not work on Android
Look dude, I'm trying to help you here.. But you only say stuff don't work and 'thumb-down' me, without posting any errors or code samples... So good luck solving your issues.
So I'm trying to set this up, and as far as I can tell, the onNotification callback is not called when notification is received, only when it's tapped on (and that works on debug and release).
@hedshafran @ljuborados I'm also facing error when I get notification only I'm on forgreound and not in background without any error. how can I fix it?
@adirzoari honestly I haven't found a fix, but I only needed this for scheduled local notifications, so I'm just saving each notification to the store, and filtering them depending on current time, it's a really hacky solution but at least it works.. I am using OneSignal for push notifications, and with OneSignal I haven't had a single issue, even though they collect (a lot) of user data - so that might be a big minus depending on your use case..
Do you have example that run with onesignal?
@adirzoari I was using react-native-onesignal, there is an example in the repo
I have tested here, but it's really don't working in Background. I executed the app using react-native run-android --variant=release
I wrote a simple code:
const notification = new firebase.notifications.Notification();
const date = new Date();
date.setSeconds(date.getSeconds() + 5);
notification
.setSound("default")
.setNotificationId('quiz')
.setTitle(`Olá, `)
.setBody('Nos ajude respondendo algumas perguntas.')
.setData({
action: 'openOut',
value: 'https://www.winsocial.com.br'
});
if (Platform.OS === 'android') {
notification.android
.setChannelId('winsocial')
.android.setPriority(firebase.notifications.Android.Priority.Max);
}
// date.setMinutes(date.getMinutes() + 1);
firebase
.notifications()
.scheduleNotification(notification, {
fireDate: date.getTime()
})
.catch(err => alert(err.message));
i have same issue anybody can solve it ?
Same issue
I have same issue @shaikhussian, but i solve with adding default_notification_channel_id in the AndroidManifest.xml
<meta-data android:name="com.google.firebase.messaging.default_notification_channel_id" android:value="@string/default_notification_channel_id" />
and res/values/strings.xml
<string name="default_notification_channel_id">YOUR_CHANNEL_ID</string>
https://github.com/invertase/react-native-firebase/issues/2215#issuecomment-518687184
I am able to get the notification when my app is running means foreground. but when the app is background it didn't receive any notification. I am using firebase so when data is added to firebase then it well triggers that function. my code is:
class CustomerMainScreen extends Component { constructor(props){ super(props); this.state = { uid:'', mechaniclocation:'', problemlocation:'', problemid:'', timeanddate: new Date().toLocaleString(), } this.notif = new NotifService(); } componentDidMount(){ firebase.database().ref('Problems').on('child_added', snapshot => { this.notif.localNotif(); } } }
I need to show notification content with in app. For foreground I am able to show notification content with in app. But when app is in background I can't. When user tap on notification in background, i want to show that notification content with in app. Can any one help me to fix this?
Thanks in advance!