invertase / notifee

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

Issue resolving URL in attachment in iOS #968

Closed zirho closed 10 months ago

zirho commented 10 months ago

Hey guys,

I am trying to reason about or understand better with an error I am getting when showing a notification with an image url on an iOS app.

I have an app that upload a file attaching to a post and show it on web/mobile.

From web, it works just fine all around. uploading/showing the image on notifications also works fine. On mobile (iOS RN), it shows this error and image is not showing up.

Both image urls are publicly available (attached at the bottom) and you can open them just fine with browser / in-app as well.

The error message that I get is this

image

2024-01-18 22:43:21.246110-0800 TtoPet73[18769:26124771] NotifeeCore: An error occurred whilst trying to resolve an attachment {
    id = kZFIElNv0spdgpNaxURR;
    thumbnailHidden = 0;
    url = "https://storage.googleapis.com/ttopet-uploads/uploads/thumbnail_hello_755c44ce00/thumbnail_hello_755c44ce00.jpeg";
}: Error Domain=UNErrorDomain Code=101 "Unrecognized attachment file type" UserInfo={NSLocalizedDescription=Unrecognized attachment file type}

How I show notifications in RN

                const data = {
                  title: 'title',
                  body: 'body',
                  ios: {
                    attachments: [
                      {
                        url: 'https://storage.googleapis.com/ttopet-uploads/uploads/thumbnail_hello_755c44ce00/thumbnail_hello_755c44ce00.jpeg',
                      },
                    ],
                  },
                };

                notifee.displayNotification(data);

The images. They are from the same image files.

  1. Uploaded from mobile (not working for notification) https://storage.googleapis.com/ttopet-uploads/uploads/thumbnail_hello_755c44ce00/thumbnail_hello_755c44ce00.jpeg
  2. Uploaded from web (WORKS) https://storage.googleapis.com/ttopet-uploads/uploads/thumbnail_from_web_82e2a57d61/thumbnail_from_web_82e2a57d61.jpg

I looked at the notifiee code and spot the location that error is from.

https://github.com/invertase/notifee/blob/main/ios/NotifeeCore/NotifeeCoreUtil.m#L159-L167 But I don't know how to continue investigation from here.

Unrecognized attachment file type And this could be related to type defined here. I've tried some values from here but no luck. https://developer.apple.com/documentation/usernotifications/unnotificationattachment#1682051

Any insights, thoughts or direction would be appreciated.

Thanks

zirho commented 10 months ago

Found the fix

https://notifee.app/react-native/reference/iosnotificationattachment#typehint

{
   url: 'some-url',
   typeHint: 'public.jpeg',
}

did the trick.