Фикс: пуш-аватарки (Communication Notification entitlement) + in-app баннер 1:1 Telegram parity

This commit is contained in:
2026-04-08 01:03:13 +05:00
parent bde2e78f3d
commit f6af59ba11
6 changed files with 67 additions and 25 deletions

View File

@@ -497,6 +497,9 @@ final class NotificationService: UNNotificationServiceExtension {
UIGraphicsEndImageContext()
guard let pngData = image?.pngData() else { return nil }
if let tempURL = storeTemporaryImage(data: pngData, key: "letter-\(key)", fileExtension: "png") {
return INImage(url: tempURL)
}
return INImage(imageData: pngData)
}
@@ -532,6 +535,9 @@ final class NotificationService: UNNotificationServiceExtension {
UIGraphicsEndImageContext()
guard let pngData = image?.pngData() else { return nil }
if let tempURL = storeTemporaryImage(data: pngData, key: "group-\(key)", fileExtension: "png") {
return INImage(url: tempURL)
}
return INImage(imageData: pngData)
}
@@ -550,6 +556,9 @@ final class NotificationService: UNNotificationServiceExtension {
guard !normalized.isEmpty else { continue }
let avatarURL = avatarsDir.appendingPathComponent("\(normalized).jpg")
if let data = try? Data(contentsOf: avatarURL), !data.isEmpty {
if let tempURL = storeTemporaryImage(data: data, key: "photo-\(normalized)", fileExtension: "jpg") {
return INImage(url: tempURL)
}
return INImage(imageData: data)
}
}
@@ -593,6 +602,28 @@ final class NotificationService: UNNotificationServiceExtension {
.lowercased()
}
/// Writes image data to NSTemporaryDirectory so INImage can reference it via file URL.
/// Telegram approach: INImage(imageData:) is unreliable in NSE file URL works.
private static func storeTemporaryImage(data: Data, key: String, fileExtension: String) -> URL? {
let imagesPath = NSTemporaryDirectory() + "aps-data"
try? FileManager.default.createDirectory(
at: URL(fileURLWithPath: imagesPath),
withIntermediateDirectories: true
)
let fileName = key.replacingOccurrences(of: "/", with: "_")
let tempURL = URL(fileURLWithPath: imagesPath)
.appendingPathComponent("\(fileName).\(fileExtension)")
if FileManager.default.fileExists(atPath: tempURL.path) {
return tempURL
}
do {
try data.write(to: tempURL, options: [.atomic])
return tempURL
} catch {
return nil
}
}
// MARK: - Helpers
/// Android parity: extract sender key from multiple possible key names.