0

我在我的应用程序中使用 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]]];

                       });

但都没有奏效。请帮助并告诉我我做错了什么。

4

0 回答 0