如何在推送通知中加载图片?

时间:2019-01-27 16:07:15

标签: ios objective-c push-notification unnotificationattachment

我在我的应用程序中使用UNNotificationContentExtension为推送通知创建自定义UI。通知有效负载包含要显示的图像的URL。我可以下载图像并将其保存到临时位置。问题在于图像根本没有加载到通知中。这是在所有处理之后创建的UNNotificationAttachment:

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

这是我创建附件对象后尝试在didReceiveNotification中加载图像的方法:

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]]];

                       });

但是没有一个起作用。请帮忙,告诉我我在做什么错。

0 个答案:

没有答案