React-native-push-notification: onNotification not triggered when app mode is background

Created on 31 Jul 2019  Â·  9Comments  Â·  Source: zo0r/react-native-push-notification

Please help me, onNotification will never be called when app is in background mode, but it is triggered when app in foreground mode.
Can someone help me? Thanks!

All 9 comments

Please help me, onNotification will never be called when app is in background mode, but it is triggered when app in foreground mode.
Can someone help me? Thanks!

please up your code, we can fix it's

This is an iOS behavior and has nothing to do with react-native-push-notification. It behaves the same if you develop natively with Objective-C or swift.

Sent from my iPhone

Am 01.08.2019 um 03:56 schrieb tinpt123 notifications@github.com:

Please help me, onNotification will never be called when app is in background mode, but it is triggered when app in foreground mode.
Can someone help me? Thanks!

please up your code, we can fix it's

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.

Please help me, onNotification will never be called when app is in background mode, but it is triggered when app in foreground mode.
Can someone help me? Thanks!

please up your code, we can fix it's

My app entry point is

return (
        <Provider store={store}>
            <PushNotificationController/>
            <AppContainer ref={navigatorRef => {
                NavigationService.setTopLevelNavigator(navigatorRef);
            }}/>
        </Provider>
    );

Component PushNotificationController is

export const PushNotificationController = (props: PushNotificationProps) => {

    useEffect(() => {
        configurePushNotification(onRegister,onNotif)
    },[])

    const onRegister = (token: string) => {
        console.log('token', token);
    }

    const onNotif = (notif: any) => {
        console.log('notification ',notif);
        // required on iOS only (see fetchCompletionHandler docs: https://facebook.github.io/react-native/docs/pushnotificationios.html)
        notif.finish(PushNotificationIOS.FetchResult.NoData);
    }

    return (null)
};

the method configurePushNotification is the same as the example here: https://github.com/zo0r/react-native-push-notification/blob/master/example/NotifService.js

My AndroidManifest is

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.mypackage">

    <uses-permission android:name="android.permission.INTERNET" />

    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

    <application
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:allowBackup="false"
      android:theme="@style/AppTheme">
       <activity
                android:name=".SplashActivity"
                android:theme="@style/SplashScreenTheme"
                android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
       </activity>
      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:launchMode="singleTask"
        android:theme="@style/MainActivityTheme"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
        android:windowSoftInputMode="adjustResize"
        android:screenOrientation="portrait"
        android:exported="true">
      </activity>
      <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />

        <meta-data  android:name="com.dieam.reactnativepushnotification.notification_channel_name"
                    android:value="@string/channel_name"/>
        <meta-data  android:name="com.dieam.reactnativepushnotification.notification_channel_description"
                    android:value="@string/channel_description"/>
        <!-- Change the resource name to your App's accent color - or any other color you want -->
        <meta-data  android:name="com.dieam.reactnativepushnotification.notification_color"
                    android:resource="@android:color/white"/>

        <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationPublisher" />
        <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationBootEventReceiver">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>
        <service android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationRegistrationService"/>


        <service
                android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService"
                android:exported="false" >
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>



    </application>

</manifest>

This is an iOS behavior and has nothing to do with react-native-push-notification. It behaves the same if you develop natively with Objective-C or swift.
…
Sent from my iPhone
Am 01.08.2019 um 03:56 schrieb tinpt123 @.*>: Please help me, onNotification will never be called when app is in background mode, but it is triggered when app in foreground mode. Can someone help me? Thanks! please up your code, we can fix it's — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

My problem is android os

@Hanf92 is this problem solved? how?

@Hanf92 is this problem solved? how?

Oh yes, need to add this function on componentDidMount hook PushNotification.popInitialNotification and the message from firebase must be "GCM": "{ \"data\": { \"message\": \"Test, ignore this message.\", \"title\": \"SOLDO test\"} }"

popInitialNotification works when app is killed, but it's not called when app is in bacgkround

@tommypd - facing same issue.

@tommypd - facing same issue . onNotification not triggered when app is in background.But works when killed/foreground state

Was this page helpful?
0 / 5 - 0 ratings