question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Notification without popups in background

See original GitHub issue

Hello, i have a problem with notification when app is in background or killed. I can receive notification from firebase but i can see only the icon on icon try, the popup never appears when app is in background or not running. Can some one help me?


componentWillMount(){
		// If user isn't logged in goto LoginScreen 
		if( this.props.Auth.token === null ) {
			this.props.navigation.navigate('AuthScreen');
		} 

		FCM.requestPermissions()
			.then((garanted) => {
				if(garanted) {
					this._setToken();
				}
			})
			.catch(()=>console.error('notification permission rejected'));

		this._notificationListener = FCM.on(FCMEvent.Notification, async (notif) => {
			// optional, do some component related stuff
			console.log('ON Notification', notif);
			// there are two parts of notif. notif.notification contains the notification payload, notif.data contains data payload
			if(notif.local_notification){
				//this is a local notification
				console.log('local notification');
			}
			if(notif.opened_from_tray){
				console.log('opened_from_tray');
				//iOS: app is open/resumed because user clicked banner
				//Android: app is open/resumed because user clicked banner or tapped app icon
			}
			// await someAsyncCall();

			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 https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623013-application.
				//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;
				}
			}
			if(notif.data) {
				//console.log( JSON.parse(notif.data));
				//this._sendRemote(notif);
			}
		});
		
		FCM.getInitialNotification().then(notif => {
			console.log('initials: ', notif);
			//do something with notification
		});
	}

	componentDidUpdate() {}

	componentWillUnmount = () => {
		this._notificationListener.remove();
	}

	_setToken = () => {
		FCM.getFCMToken().then(token => {
			this.props.setFCMToken(token);
		});	
	}

	_sendRemote = notif => {
		FCM.presentLocalNotification({
			title: notif.fcm.title,                     // as FCM payload
			body: notif.fcm.body,                    // as FCM payload (required)
			sound: "default",                                   // as FCM payload
			priority: "high",                                   // as FCM payload
			click_action: "ACTION",                             // as FCM payload
			auto_cancel: true,                                  // Android only (default true)
			vibrate: 300,                                       // Android only default: 300, no vibration if you pass 0
			wake_screen: true,                                  // Android only, wake up screen when notification arrives
			lights: true,                                       // Android only, LED blinking (default false)
			show_in_foreground: true                                  // notification when app is in foreground (local & remote)        
		});
	}

Env: RN 0.48.4 react-native-fcm: 11.2.0 Im using a Samsung Galaxy S7 and app is in background;

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

3reactions
mts88commented, Jan 19, 2018

@Donhv i tested only on android. So, i send a structure like this:

{
	"to" : <TOKEN_DEVICE>,
	"content_available": true,
	"data": {
		"custom_notification": {
		   "title": "hello",
		   "body": "yo",
		   "click_action": "fcm.ACTION.PUSH",
		   "priority":"high",
		   "show_in_foreground": true
		}
	}
}

to Firebase REST API (see this for documentation) Hope help u.

0reactions
imjaadHcommented, Oct 6, 2018

@qDanik would you share the listener code

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Stop Pop-Ups in Windows 10 and 11 - MakeUseOf
Seeing pop-ups and not sure where they came from? Here's a quick guide to diagnosing and dealing with Windows pop-ups.
Read more >
Prevent Popup Notifications from Appearing on Your Windows ...
To turn off the notifications, you need to go to Windows Settings > System > Notifications & Actions. Under the Notifications section, turn...
Read more >
Push notifications do not pop up in background mode
Implemented push notifications several times and all worked fine, from my backend ... Push notifications do not pop up in background mode.
Read more >
Change notification and quick settings in Windows
Learn how to change your notification settings and quick actions using the notification center in Windows.
Read more >
How to block all vendor-app notification and bottom-right ...
(A) Settings method that catches many notifications. Start, Settings, System, Notifications and scroll down the right side.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found