0

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.

CloudSaver
  • 11
  • 5
Ghazalah
  • 233
  • 2
  • 14
  • 1
    follow this blog : https://medium.com/@lucasgoesvalle/custom-push-notification-with-image-and-interactions-on-ios-swift-4-ffdbde1f457 – Rishil Patel Jan 27 '19 at 19:16
  • @RishilP. I had already seen this blog, but when I went through it again after getting suggested by you, I noticed a difference from all other sites. In majority of blogs or tutorials its suggested to save the downloaded image in a temprory location in the Filehandler, while this blog suggests to just store the image's NSData and convert it to UIImage when required. And that did the trick. Thanks man !! – Ghazalah Feb 05 '19 at 11:44

0 Answers0