invertase / notifee

⚛️ A feature rich notifications library for React Native.
https://notifee.app
Apache License 2.0
1.88k stars 228 forks source link

Vibration doesn’t work for background notifications #921

Closed ArtemBozhenko closed 11 months ago

ArtemBozhenko commented 1 year ago

I am facing problems with vibrating on my android phone. It doesn’t work for background notifications, but works fine for foreground notifications.

index.js file

import { AppRegistry } from 'react-native';
import { name as appName } from './app.json';
import App from './src/index';
import { initNotifee } from '#config/notifications/initNotifee';

initNotifee();

AppRegistry.registerComponent(appName, () => App);

initNotifee.ts file

const onMessageReceived = async (message: FirebaseMessagingTypes.RemoteMessage) => {
  const { notification } = message;

  const body = notification?.body || '';
  const title = notification?.title || '';

  const config: Notification = {
    id: Config.NOTIFICATION_CHANNEL_ID,
    title,
    body,
    android: {
      importance: AndroidImportance.HIGH,
      channelId: Config.NOTIFICATION_CHANNEL_ID,
      smallIcon: "@mipmap/ic_notification",
    },
  };
  await notifee.displayNotification(config);

};

export const initNotifee = async () => {
  try {
    messaging().setBackgroundMessageHandler(onMessageReceived);

    notifee.createChannel({
      id: config.NOTIFICATION_CHANNEL_ID,
      name: 'default channel',
      vibration: true,
      badge: true,
      importance: AndroidImportance.HIGH,
    });
  } catch (err) {
    return false;
  }
};

Sending push via firebase test message

Any ideas what's wrong? I checked application settings for notification. They allowed for vibrations.

shahanaahmad commented 11 months ago

I am also facing the same issue, is there any update on this?

ArtemBozhenko commented 11 months ago

I am also facing the same issue, is there any update on this?

Just double check your NOTIFICATION_CHANNEL_ID and send test notification via firebase "New campaign", should work When your backend will send notification, he must put your NOTIFICATION_CHANNEL_ID in android config