How to load image in push notification?

579 Views Asked by At

I am using UNNotificationContentExtension in my app to create a custom UI for the push notifications. The notification payload contains url for the image to be displayed. I am able to download and save the image to a temporary location. The problem is that the image is not loading in the notification at all. This is the UNNotificationAttachment created after all the processing:

UNNotificationAttachment: 0x2820bfc30; identifier: DFEAC8A3-8B9E-4FFA-9CC4-3D7B3EE62F74, family: Image, URL: file:///private/var/mobile/Containers/Data/PluginKitPlugin/EF8FAE09-D295-485F-99FD-9BF2BE3628B4/tmp/CFNetworkDownload_bfL88G.tmp.jpg, type: public.jpeg, options: UNImageNotificationAttachmentOptions: 0x283bb6800

This is how I tried to load the image in didReceiveNotification after creating the attachment object:

dispatch_async(dispatch_get_main_queue(), ^{
                           self->notificationImageVw.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@",attachment.URL]];

                           [self->notificationImageVw setImage:[UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@",attachment.URL]]];


                           self->notificationImageVw.image = [UIImage imageWithContentsOfFile:[[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@",attachment.URL]]];

                       });

But none of it worked. Please help and tell me what I'm doing wrong.

0

There are 0 best solutions below