Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[question]: Handling data (with content_available=true) notifications #1782

Open
1 task done
max-baykalov opened this issue Jan 25, 2025 · 0 comments
Open
1 task done

Comments

@max-baykalov
Copy link

max-baykalov commented Jan 25, 2025

How can we help?

We use OneSignal to handle notifications on Expo project. I faced an problem on version of react-native-onesignal: 5.2.5.

Code to catch notification in Expo app:

import { LogLevel, NotificationWillDisplayEvent, OneSignal } from 'react-native-onesignal';

...

const eventListener = (event: NotificationWillDisplayEvent) => {
    console.log(event);

    event.getNotification().display();
  };

  useEffect(() => {
    OneSignal.initialize(Constants?.expoConfig?.extra?.oneSignalAppId);
    OneSignal.Debug.setLogLevel(LogLevel.Verbose);
    OneSignal.Notifications.requestPermission(true);
    OneSignal.Notifications.addEventListener('foregroundWillDisplay', eventListener);

    return () => OneSignal.Notifications.removeEventListener('foregroundWillDisplay', eventListener);
  }, []);

The console.log in the eventListener method is triggered in case of data only notification. It works only when contents field is set. I assume this is correct behaviour because foregroundWillDisplay event must not be triggered when notification should not be displayed.

I need to handle data notifications when the expo app is in the foreground mode to refetch user's data. I send the following notification from the server:

Notification data

Notification {
  app_id: 'APP_ID',
  include_aliases: { external_id: [ 'USER_ID' ] },
  target_channel: 'push',
  data: { foo: 'bar' },
  content_available: true
}

Is there any way to intercept data notifications in JS code?

Thanks for any help.

Code of Conduct

  • I agree to follow this project's Code of Conduct
@max-baykalov max-baykalov changed the title [question]: Handling data (with content_available-true) notifications [question]: Handling data (with content_available=true) notifications Jan 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant