Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

onNotification is not calling when app is in background #1431

@rizwanshaikh199091

Description

@rizwanshaikh199091

Bug

When I am calling fcm server push notification api data is not showing on onNotification function.

Environment info

react-native info output:

 // paste it here

Library version: 3.4.0

Steps To Reproduce

I use the following code for recieving push notification

  1. Call the service from postman collection for fcm
  2. we got data in onNotification when app is in foreground but not in backgorund
    ...

Describe what you expected to happen:

Reproducible sample code

PushNotification.configure({
// (optional) Called when Token is generated (iOS and Android)
onRegister: function (token) {
console.log("TOKEN:", token);
thats.setState({deviceToken:token});
},

  // (required) Called when a remote or local notification is opened or received
  onNotification: function (notification) {
    

    console.log('** NOTIFICATION: **', notification);

  if (Platform.OS === 'ios') {
    if (notification.alert.length !== 0) {
      //handleNotification(notification)
      notification.finish(PushNotificationIOS.FetchResult.NoData);
    }
  } else {
    //handleNotification(notification)
  }

  
  },

  // IOS ONLY (optional): default: all - Permissions to register.
  permissions: {
    alert: true,
    badge: true,
    sound: true,
  },

  // Should the initial notification be popped automatically
  // default: true
  popInitialNotification: true,

 
  requestPermissions: true,
});

PushNotification.popInitialNotification((notification) => { 
  console.log(notification); 
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions