diff --git a/ElementX/Sources/Other/Extensions/UNNotificationContent.swift b/ElementX/Sources/Other/Extensions/UNNotificationContent.swift index 3d9adbf10..c27450e89 100644 --- a/ElementX/Sources/Other/Extensions/UNNotificationContent.swift +++ b/ElementX/Sources/Other/Extensions/UNNotificationContent.swift @@ -122,7 +122,7 @@ extension UNMutableNotificationContent { if let fetchedImage { image = fetchedImage } else if let data = await getPlaceholderAvatarImageData(name: icon.groupInfo?.name ?? senderName, - id: icon.groupInfo?.name ?? senderName) { + id: icon.groupInfo?.id ?? senderID) { image = INImage(imageData: data) } else { image = INImage(named: "") @@ -181,6 +181,31 @@ extension UNMutableNotificationContent { .clipShape(Circle()) .frame(width: 100, height: 100) let renderer = await ImageRenderer(content: image) - return await renderer.uiImage?.jpegData(compressionQuality: 0.8) + guard let image = await renderer.uiImage else { + return nil + } + + // On simulator and macOS the image is rendered correctly + // But on other devices is rendered upside down so we need to flip it + #if targetEnvironment(simulator) + return image.pngData() + #else + if ProcessInfo.processInfo.isiOSAppOnMac { + return image.pngData() + } else { + return image.flippedVertically().pngData() + } + #endif + } +} + +private extension UIImage { + func flippedVertically() -> UIImage { + let format = UIGraphicsImageRendererFormat() + format.scale = scale + return UIGraphicsImageRenderer(size: size, format: format).image { context in + context.cgContext.concatenate(CGAffineTransform(scaleX: 1, y: -1)) + self.draw(at: CGPoint(x: 0, y: -size.height)) + } } } diff --git a/changelog.d/1194.bugfix b/changelog.d/1194.bugfix new file mode 100644 index 000000000..22d3895c5 --- /dev/null +++ b/changelog.d/1194.bugfix @@ -0,0 +1 @@ +Fix for the flipped notification image placeholder on iOS. \ No newline at end of file