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

Local notification with local image #1142

Open
trajano opened this issue Nov 9, 2024 · 5 comments
Open

Local notification with local image #1142

trajano opened this issue Nov 9, 2024 · 5 comments

Comments

@trajano
Copy link

trajano commented Nov 9, 2024

#931 talks about a remote image.

For now I just want to download an image store it in the "cache" folder so the attachment looks like this

[
  {
    "id": "633435dcb418833920a16771610ca404", 
    "thumbnailHidden": false,
    "thumbnailTime": 0, 
    "typeHint": "public.png", 
    "url": "file:///var/mobile/Containers/Data/Application/082B40E9-4209-4FC3-9165-BD7C57591E47/Library/Caches/ExponentAsset-633435dcb418833920a16771610ca404.png"
  }
]

I've tried different variants removing values for ID type etc. With no luck

But the thumbnail image is not appearing

requires approach does work though.

Looking at the examples folder you're using a remote image.

Code https://github.com/trajano/expo-experiments/blob/test-expand-idea/packages/my-app/src/stories/Notification.stories.tsx

@mikehardy
Copy link
Contributor

seems to be well supported at least in theory

https://github.com/invertase/notifee/blob/ae2953b7d0a0881f7bb925f0f5d0cf1d3ac9daf4/packages/react-native/src/types/NotificationIOS.ts#L624C69-L624C161

as long as it is a local file of supported type and within size limits (https://developer.apple.com/documentation/usernotifications/unnotificationattachment#1682051)

I assume it works if the file is in the bundle? it's just downloading a local file first then trying to display it that is not working?

Adding instrumentation logs here and running from Xcode may be instructive

+ (UNNotificationAttachment *)attachmentFromDictionary:(NSDictionary *)attachmentDict {

There is not a lot of logic between the line where files are resolved and content is packaged then sent to the iOS notification center here

UNMutableNotificationContent *content = [self buildNotificationContent:notification

@trajano
Copy link
Author

trajano commented Nov 10, 2024

It's failing with a copy from the bundle. If we use the "bundle" via require it works. The image itself is small, but there's a small hint in that document you provided

/**
* A URL to the media file to display.
*
* The value can be any of the following:
*
* - An absolute path to a file on the device
* - iOS resource
*
* For a list of supported file types, see [Supported File Types](https://developer.apple.com/documentation/usernotifications/unnotificationattachment#1682051) on the official Apple documentation for more information.
*/
url: string;

The key part is absolute path meaning the uri which I normally pass in as file:///... may have an issue

@trajano
Copy link
Author

trajano commented Nov 10, 2024

Thar we go

    return assets
      .filter((it) => it)
      .map((it) => ({
        id: it.hash!,
        thumbnailHidden: false,
        typeHint: `public.${it.type}`,
        url: it.localUri!.substring('file://'.length),
      }));

The documentation should note or at least specify that a url is a PATH and file:// shouldn't prefix it.

In case anyone is wondering... "expo-notifications" does not work even with the removal of the file:// prefix

But this will break on the second usage of the notification with the same URL because the file moves as alluded to by iOS documentation, knew that before hand so just have to tweak the thing a bit

trajano added a commit to trajano/expo-experiments that referenced this issue Nov 10, 2024
This makes a clone of the list and strips off the file:// prefix on the
URL

invertase/notifee#1142
@trajano
Copy link
Author

trajano commented Nov 10, 2024

@mikehardy
Copy link
Contributor

@trajano that's fantastic you got something working! That's always the first step :-) - I think you're easily the subject matter expert here at the moment, I'd be happy to merge any reasonable PR that improved this area, and the release pipeline has been exercised recently + commit queue is clean so getting it out would be quick

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

2 participants