Describe your issue here
First of all, the app only is receiving the notifications when is in foreground. If the app is in background, the notification will not shown and the listener doesn't enter as expected, but, when i open the app the listener get the notification.
I just add the APNs Key to the firebase console, and re-download and add to the project the GoogleService-info.plist and checked the the "Background Modes -> Remote notification" and the "Push Notification" items under Capabilities in XCode and i'm not using pods for RNF
The second thing is, whenever i send a notification or a data-only message, the app listen it as a notification always getting body, title, sound, etc. as _undefined_, and the key "notification" its inside data, even if i never send data in the notification and it gets a new key (not sended by me) e: "1", like this:
Notification {
_body: undefined,
_data: {
from: "591699987834",
notification: {
body: "test",
e: "1",
title: "prueba",
__proto__: Object
},
__proto__: Object
},
_ios: {
_notification: Notification,
_alertAction: undefined,
_attachments: Array(0),
_badge: undefined,
_category: undefined,
},
_notificationId: "-LemY1Pf-aM0PK4a3oRb",
_sound: undefined,
_subtitle: undefined,
_title: undefined,
android: (...),
body: (...),
data: (...),
ios: (...),
notificationId: (...),
sound: (...),
subtitle: (...),
title: (...),
__proto__: Object
}
`
export default class NotificationsHandler extends Component
componentDidMount() {
const {
onNavigate,
onGetAssigned,
onFCMMessage,
onSelect,
token,
cuit,
} = this.props;
if (Config.FCM === 'true') {
this.registerFCM();
// Build a channel
const channel = new firebase
.notifications
.Android
.Channel('mobile-prestadores', 'Prestadores Channel', firebase.notifications.Android.Importance.Max)
.setDescription('Swiss Medical Prestadores');
firebase.notifications().android.createChannel(channel);
this.addFCMMessageListener();
}
firebase.notifications().getInitialNotification()
.then((notificationOpen) => {
if (notificationOpen) {
const notification = { ...notificationOpen.notification };
let service = { ...notification.data };
token ? this.manageClickNotification(service) : this.props.onNavigate(constants.navigation.login);
}
});
}
manageRecieveNotifications = service => {
let serviceFormated;
this.props.onFCMMessage(serviceFormated);
}
manageClickNotification = service => {
let serviceFormated;
this.props.onFCMMessage(serviceFormated);
}
componentWillUnmount() {
this.removeListeners();
}
registerFCM() {
const {
onFCMRegister,
} = this.props;
return requestGCMPermissions().then((fcm) => {
if (fcm) {
firebase.messaging().getToken().then((fcmToken) => {
if (fcmToken) {
console.log(fcmToken);
onFCMRegister(fcmToken);
} else {
firebase.messaging().onTokenRefresh((newToken) => {
console.log(fcmToken);
onFCMRegister(newToken);
});
}
});
}
});
}
addFCMMessageListener() {
const {
onUpdatePush,
onFCMMessage,
onNavigate,
onGetAssigned,
onSelect,
token,
cuit,
} = this.props;
this.messageListener = firebase.messaging().onMessage((message) => {
let service = message.data;
this.manageRecieveNotifications(service);
});
this.notificationDisplayedListener =
firebase.notifications().onNotificationDisplayed((notification) => {
let service = notification.data;
this.manageRecieveNotifications(service);
});
this.notificationListener =
firebase.notifications().onNotification((notification) => {
let service = notification.data;
service = formatters.pushFormat(service);
console.log("notification", notification)
this.manageRecieveNotifications(service);
});
this.notificationOpenedListener =
firebase.notifications().onNotificationOpened((notificationOpen) => {
// Get the action triggered by the notification being opened
const notification = { ...notificationOpen.notification };
let service = { ...notification.data };
service = formatters.pushFormat(service);
token ? this.manageClickNotification(service) : onNavigate(constants.navigation.login);
});
}
removeListeners() {
const { listener } = this.props.location;
if (listener) {
navigator.geolocation.clearWatch(this.watchId);
}
if (this.messageListener) {
this.messageListener();
}
if (this.notificationDisplayedListener) {
this.notificationDisplayedListener();
}
if (this.notificationOpenedListener) {
this.notificationOpenedListener();
}
if (this.notificationListener) {
this.notificationListener();
}
}
render() {
return(
)
}
}
`
ios/Podfile:# N/A
AppDelegate.m://App Delegate.m
#import "AppDelegate.h"
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <RNSplashScreen.h>
#import <ReactNativeConfig.h>
#import <NewRelicAgent/NewRelic.h>
#import "Firebase.h"
#import "RNFirebaseNotifications.h"
#import "RNFirebaseMessaging.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSURL *jsCodeLocation;
NSString *newrelicToken = [ReactNativeConfig envFor:@"NEWRELIC_IOS_TOKEN"];
[NewRelicAgent startWithApplicationToken:newrelicToken];
[FIRApp configure];
[RNFirebaseNotifications configure];
jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
//jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"Prestadores"
initialProperties:nil
launchOptions:launchOptions];
rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIViewController *rootViewController = [UIViewController new];
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
[RNSplashScreen show];
return YES;
}
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
[[RNFirebaseNotifications instance] didReceiveLocalNotification:notification];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo
fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler{
[[RNFirebaseNotifications instance] didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
}
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
[[RNFirebaseMessaging instance] didRegisterUserNotificationSettings:notificationSettings];
}
@end
// N/A
Click To Expand
#### `android/build.gradle`:
// N/A
#### `android/app/build.gradle`:
// N/A
#### `android/settings.gradle`:
// N/A
#### `MainApplication.java`:
// N/A
#### `AndroidManifest.xml`:
<!-- N/A -->
"react-native": "0.59.4",
"react-native-firebase": "5.3.1",
react-native info output:
OUTPUT GOES HERE
Firebase module(s) you're using that has the issue:e.g. Instance IDTypeScript?N
Think react-native-firebase is great? Please consider supporting all of the project maintainers and contributors by donating via our Open Collective where all contributors can submit expenses. [Learn More]
React Native Firebase and Invertase on Twitter for updates on the library.Hello 馃憢, to help manage issues we automatically close stale issues.
This issue has been automatically marked as stale because it has not had activity for quite some time. Has this issue been fixed, or does it still require the community's attention?
This issue will be closed in 15 days if no further activity occurs.
Thank you for your contributions.
Closing this issue after a prolonged period of inactivity. If this is still present in the latest release, please feel free to create a new issue with up-to-date information.
happens for me too