Retrieving Images Sent with the Notification Composer in iOS

121 views
Skip to first unread message

Alberto Vecchi

unread,
Aug 5, 2021, 11:13:20 AM8/5/21
to Firebase Google Group
Hi everyone,
I'm testing FCM on iOS.

Let's say I'm sending an image with the Notification Composer.
On Xcode, I set up a Notification Service Extension and in the didReceive(_:withContentHandler:) method I let Firebase do all the work with this call:

FIRMessagingExtensionHelper().populateNotificationContent(bestAttemptContent, withContentHandler: contentHandler)

In theory this is handling the download of the image and is caching it. Am I right?

Then in the AppDelegate class, I retrieve the url from the 
UNNotificationAttachment but when I try instantiating an UIImage from that it fails: (UIImage(contentsOfFile: imageURL)).
The UNNotificationAttachment's url is like this:
file:///var/mobile/Library/UserNotifications/6FA[...]B84E9F7/Attachments/527[...]fc.jpeg

My question is then:
how can I properly retrieve the image from the UNNotificationAttachment and load it into an UIImage? Without downloading it again in AppDelegate.
What I understood is that Firebase has already done that and cached in local storage. But I'm not able to load it in code.

Thank you
Reply all
Reply to author
Forward
0 new messages