From 6b4a0796c3ffc607f3a2880615bc32912b839d74 Mon Sep 17 00:00:00 2001 From: Toomas Vahter Date: Wed, 19 Jun 2024 14:09:46 +0300 Subject: [PATCH] Fallback to jpeg path extension if the downloaded file does not specify it (UNNotificationAttachment requires path extension) (#3257) --- DemoAppPush/NotificationService.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/DemoAppPush/NotificationService.swift b/DemoAppPush/NotificationService.swift index 13b808ff6c4..dac40e426c9 100644 --- a/DemoAppPush/NotificationService.swift +++ b/DemoAppPush/NotificationService.swift @@ -28,7 +28,11 @@ class NotificationService: UNNotificationServiceExtension { return } - let localURL = URL(fileURLWithPath: path).appendingPathComponent(url.lastPathComponent) + // UNNotificationAttachment requires path extension to be set (fallback to jpeg if not set) + var localURL = URL(fileURLWithPath: path).appendingPathComponent(UUID().uuidString + url.lastPathComponent) + if localURL.pathExtension.isEmpty { + localURL.appendPathExtension("jpeg") + } do { try FileManager.default.moveItem(at: downloadedUrl, to: localURL)