invertase / notifee

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

IOS attach image not display when notification runs background #901

Closed ErinTran535 closed 11 months ago

ErinTran535 commented 1 year ago

notification when run background:

image

when runs foreground:

image

they are the same notification with the same payload from Firebase, this doesn't happen with Android, my Notifee version right now is 5.7.0, I've tried to fix this by upgrading the version to newest 7.8.0 but it didn't solve anything

my ios full configuration:

import notifee, { Notification, EventType, Event } from '@notifee/react-native';

import { ExceptionManager } from 'features/ExceptionManager';
import logger from 'utils/logger';
import {
  IBaseNotificationService,
  IRemoteDataForLocalNotificationPayload
} from 'features/Notification/BaseNotificationHandler';

export class IOSLocalNotificationService implements IBaseNotificationService {
  defaultBackgroundHandler = async ({ type, detail }: Event): Promise<void> => {
    if (type === EventType.DISMISSED) {
      logger.info('User dismissed notification', detail);
    }
    if (type === EventType.DELIVERED) {
      logger.info('Delivered notification', detail);
    }
    if (type === EventType.PRESS) {
      logger.info('User pressed the notification.', detail.pressAction?.id);
    }
  };

  defaultForegroundHandler = async ({ type, detail }: Event): Promise<void> => {
    if (type === EventType.APP_BLOCKED) {
      logger.info('User toggled app blocked', detail);
    }

    if (type === EventType.CHANNEL_BLOCKED) {
      logger.info('User toggled channel block', detail);
    }

    if (type === EventType.CHANNEL_GROUP_BLOCKED) {
      logger.info('User toggled channel group block', detail);
    }
  };

  private getDefaultIOSNotificationOptions(payload: Partial<IRemoteDataForLocalNotificationPayload>): Notification {
    const options = {
      id: payload.id,
      title: payload.title || 'Missing notification title',
      body: payload.body || 'Missing notification body',
      data: { data: JSON.stringify(payload.data) || '' },
      ios: {
        foregroundPresentationOptions: {
          alert: true,
          badge: true,
          sound: true,
        },
        sound: 'default',
      },
    } as Notification;
    if (payload.image && options.ios) {
      options.ios.attachments = [{ url: payload.image }];
    }

    return options;
  }

  async registerService(): Promise<void> {}

  async registerForegroundHandler(handler = this.defaultForegroundHandler): Promise<() => void> {
    return notifee.onForegroundEvent(handler);
  }

  async registerBackgroundHandler(handler = this.defaultBackgroundHandler): Promise<void> {
    notifee.onBackgroundEvent(handler);
  }

  async displayNotification(payload = {} as IRemoteDataForLocalNotificationPayload): Promise<string> {
    try {
      return await notifee.displayNotification(this.getDefaultIOSNotificationOptions(payload));
    } catch (e) {
      ExceptionManager.captureException(e);

      return '';
    }
  }

  async cancelNotification(notificationId: string): Promise<void> {
    await notifee.cancelNotification(notificationId);
  }
}

export const IOSLocalNotificationServiceInstance = new IOSLocalNotificationService();
github-actions[bot] commented 1 year ago

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

megabeehothanhminh commented 10 months ago

How to fix?

racic99 commented 9 months ago

Does anyone have an idea how to fix this?

jdarshan5 commented 6 months ago

+1