From 64c5ee0fe971a14a1de7d50f39fc5598c17fc46f Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Thu, 8 Jan 2026 23:10:22 +0800 Subject: [PATCH] :bug: Trying to fix NSE attachment doesn't work as expected on the default types --- .../NotificationService.swift | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ios/SolianNotificationService/NotificationService.swift b/ios/SolianNotificationService/NotificationService.swift index 01cd8b2d..a8cdc39b 100644 --- a/ios/SolianNotificationService/NotificationService.swift +++ b/ios/SolianNotificationService/NotificationService.swift @@ -5,7 +5,7 @@ // Created by LittleSheep on 2025/5/31. // -import UserNotifications +@preconcurrency import UserNotifications import Intents import Kingfisher import UniformTypeIdentifiers @@ -149,7 +149,7 @@ class NotificationService: UNNotificationServiceExtension { let dispatchGroup = DispatchGroup() var attachments: [UNNotificationAttachment] = [] - let lock = NSLock() // To synchronize access to the attachments array + let queue = DispatchQueue(label: "dev.solsynth.solian.nse") for attachmentUrl in attachmentUrls { guard let remoteUrl = URL(string: attachmentUrl) else { @@ -163,7 +163,7 @@ class NotificationService: UNNotificationServiceExtension { .processor(scaleProcessor) ] : nil) { [weak self] result in defer { dispatchGroup.leave() } - guard let self = self else { return } + guard self != nil else { return } switch result { case .success(let retrievalResult): @@ -176,12 +176,12 @@ class NotificationService: UNNotificationServiceExtension { try retrievalResult.image.pngData()?.write(to: cachedFileUrl) if let attachment = try? UNNotificationAttachment(identifier: attachmentUrl, url: cachedFileUrl, options: [ - UNNotificationAttachmentOptionsTypeHintKey: type?.identifier as Any, + UNNotificationAttachmentOptionsTypeHintKey: UTType.png.identifier, UNNotificationAttachmentOptionsThumbnailHiddenKey: 0, ]) { - lock.lock() - attachments.append(attachment) - lock.unlock() + queue.async { + attachments.append(attachment) + } } } catch { print("Failed to write media to temporary file: \(error.localizedDescription)")