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.

onMessage not firing when application is closed state and clicking notification

See original GitHub issue

Problem

When getting notification in background state working, in app working but when app is closed user open app with notification is not working

  • In App

  • Background State? <-- I am handlind this via AppState.

  const _handleAppStateChange = async (nextAppState) => {
    if (nextAppState === 'active') {
      PushNotification.popInitialNotification((ev) => {
        setTimeout(() => {
            if (ev) {
              notifyHandler(ev);
            }
        }, 1000);
      });
    }
    setAppState(nextAppState);
  };
  • Close/Killed State <-- not getting console.log either, In Release mode is not working but debug mode sometimes works i don’t know why

Environment info

Windows 10

Library version: master branch

Steps To Reproduce

note: Notification has data and title+body too sending from backend

I am using the way library implement in Example folder same code no change

NotifyService is in react-native-push-notification/example/NotifService.js and i have NotificationHandler.js too

App.js


import NotifyService from './utils/services/notifyservice';

const notifyHandler = (data) => {
   console.log("NOTIFICATION",data);
}

function App(){
  useEffect(()=>{
        new NotifyService(saveToken, notifyHandler);
  },[])

  return(
   <Navigation stuff> // react-navigation v5
  )
}

Describe what you expected to happen:

1.Work expected in closed state 2.Also if i am not using appstate function background notification wont work

AndroidManifest file

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

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

    <uses-permission android:name="android.permission.CAMERA" />
    <uses-feature android:name="android.hardware.camera" />
    <uses-feature android:name="android.hardware.camera.autofocus"/>

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

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

    <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:usesCleartextTraffic="true"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:allowBackup="true"
      android:theme="@style/AppTheme">
      <meta-data  android:name="com.dieam.reactnativepushnotification.notification_channel_name"
              android:value="AwesomeApp"/>
      <meta-data  android:name="com.dieam.reactnativepushnotification.notification_channel_description"
                  android:value="desc"/>

      <!-- Change the value to true to enable pop-up for in foreground (remote-only, for local use ignoreInForeground) -->
      <meta-data  android:name="com.dieam.reactnativepushnotification.notification_foreground"
                  android:value="false"/>
      <!-- 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="@color/red"/> <!-- or @android:color/{name} to use a standard color -->

      <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.RNPushNotificationListenerService"
          android:exported="false" >
          <intent-filter>
              <action android:name="com.google.firebase.MESSAGING_EVENT" />
          </intent-filter>
      </service>
      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
        android:launchMode="singleTask"
        android:windowSoftInputMode="adjustResize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
      </activity>
      <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
    </application>

</manifest>

android/build.gradle

    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.2'
        classpath 'com.google.gms:google-services:4.3.3'
    }

android/app/build.gradle

dependencies {

    implementation 'com.google.firebase:firebase-analytics:17.3.0'`
}

// .. bottom
apply plugin: 'com.google.gms.google-services'

@Dallas62

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:14

github_iconTop GitHub Comments

2reactions
Dallas62commented, May 13, 2020

You can turn off popInitialNotification in the .configure method, then you will be able to call the method:

PushNotification.popInitialNotification(function(notification) {
console.log(notification);
});

Inside your component to handle properly the notification that popup the Application.

I saw documentation doesn’t mention this method, sorry for that.

1reaction
Dallas62commented, May 13, 2020

Hi @batuhansahan Can you show me the content of: NotificationHandler.js ?

To work in killed state, .configue must be called outside of a component. Since you introduced notifyHandler in the lifecycle of the App component, notifyHandler will not be called in killed state.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Firebase onMessageReceived not called when app in ...
Foreground State: The click of the notification will go to the pending Intent's activity which you are providing while creating a notification pro-grammatically ......
Read more >
Receive messages in a Flutter app - Firebase - Google
Notification messages which arrive while the application is in the foreground will not display a visible notification by default, on both Android and...
Read more >
Firebase Push Notification In React Native - Medium
Now, when the app is in the foreground state and if onMessage receives any message from firebase, PushNotification will fire local notification.
Read more >
Notifications | FlutterFire
Notifications are an important tool used on the majority of applications, aimed at improve user experience & used to engage users with your...
Read more >
Implementing Flutter Push Notifications [Top 3 Ways] - Courier
When building iOS apps with Flutter, APNs push notifications can be integrated ... onLaunch gets called, when you tap on notification on a...
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