evollu / evollu/react-native-fcm

Android: App is foreground then get notification with image and In Background then App notification not getting with image?

Open
#973 4 comments 1 reaction 0 assignees View on GitHub
Dominant language
Java
Stars
1.7k
Forks
661
PR merge metrics
No merged PRs in 30d

Description

```
componentDidMount() {
// iOS: show permission prompt for the first call. later just check permission in user settings
// Android: check permission in user settings
FCM.requestPermissions().then(()=>console.log('granted')).catch(()=>console.log('notification permission rejected'));

FCM.getFCMToken().then(token => {
console.log(token)
// store fcm token in your server
});

FCM.getInitialNotification().then(notif => {
console.log("Initial Notification", notif)
});

this.notificationListener = FCM.on(FCMEvent.Notification, notif => {
console.log("Notification", notif);

if(notif.local_notification){
console.log("local");
return;
}
if(notif.opened_from_tray){
console.log("tray");
return;
}

if(Platform.OS ==='android'){
if(!notif.local_notification){
console.log("!local");
FCM.presentLocalNotification({
title: notif.title,
body: notif.fcm.body,
priority: "high",
show_in_foreground: true,
local: true,
icon: "ic_launcher",
// color:'#008acf',
vibrate: 300,
sound: "default",
lights: true,
picture:
"https://images.pexels.com/photos/5317/food-salad-restaurant-person.jpg",

});

}
}

if(Platform.OS ==='ios'){
//optional
//iOS requires developers to call completionHandler to end notification process. If you do not call it your background remote notifications could be throttled, to read more about it see the above documentation link.
//This library handles it for you automatically with default behavior (for remote notification, finish with NoData; for WillPresent, finish depend on "show_in_foreground"). However if you want to return different result, follow the following code to override
//notif._notificationType is available for iOS platfrom
switch(notif._notificationType){
case NotificationType.Remote:
notif.finish(RemoteNotificationResult.NewData) //other types available: RemoteNotificationResult.NewData, RemoteNotificationResult.ResultFailed
break;
case NotificationType.NotificationResponse:
notif.finish();
break;
case NotificationType.WillPresent:
notif.finish(WillPresentNotificationResult.All) //other types available: WillPresentNotificationResult.None
break;
}
}

// direct channel related methods are ios only
// directly channel is truned off in iOS by default, this method enables it
FCM.enableDirectChannel();
this.channelConnectionListener = FCM.on(FCMEvent.DirectChannelConnectionChanged, (data) => {
console.log('direct channel connected' + data);
});
setTimeout(function() {
FCM.isDirectChannelEstablished().then(d => console.log("hey",d));
}, 1000);
});

this.refreshTokenListener = FCM.on(FCMEvent.RefreshToken, token => {
console.log("TOKEN (refreshUnsubscribe)", token);
});

}

componentWillUnmount() {
// stop listening for events
this.notificationListener.remove();
this.refreshTokenListener.remove();
}

@evollu
What can i do to get both notification image?

```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.