Skip to content

Commit 40026ea

Browse files
authored
Upload photos from the library as JPEG instead of HEIC (#767)
* Send photos from the library as jpeg instead of heic * Update CHANGELOG.md * Update CHANGELOG.md * Improve the name of the function
1 parent eb07dab commit 40026ea

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
44
# Upcoming
55

66
### 🔄 Changed
7+
- Uploading a HEIC photo from the library is now converted to JPEG for better compatibility [#767](https://github.com/GetStream/stream-chat-swiftui/pull/767)
78

89
# [4.73.0](https://github.com/GetStream/stream-chat-swiftui/releases/tag/4.73.0)
910
_February 28, 2025_

Sources/StreamChatSwiftUI/ChatChannel/Composer/ImagePickerView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ final class ImagePickerCoordinator: NSObject, UIImagePickerControllerDelegate, U
5555
didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]
5656
) {
5757
if let uiImage = info[.originalImage] as? UIImage,
58-
let imageURL = try? uiImage.temporaryLocalFileUrl() {
58+
let imageURL = try? uiImage.saveAsJpgToTemporaryUrl() {
5959
let addedImage = AddedAsset(
6060
image: uiImage,
6161
id: UUID().uuidString,

Sources/StreamChatSwiftUI/ChatChannel/Composer/PhotoAttachmentPickerView.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public struct PhotoAttachmentCell: View {
102102
.allowsHitTesting(true)
103103
.onTapGesture {
104104
withAnimation {
105-
if let assetURL = assetURL {
105+
if let assetURL = assetJpgURL() {
106106
onImageTap(
107107
AddedAsset(
108108
image: image,
@@ -193,4 +193,13 @@ public struct PhotoAttachmentCell: View {
193193
}
194194
}
195195
}
196+
197+
/// The original photo is usually in HEIC format.
198+
/// This makes sure that the photo is converted to JPG.
199+
/// This way it is more compatible with other platforms.
200+
private func assetJpgURL() -> URL? {
201+
guard let assetURL = assetURL else { return nil }
202+
guard let assetData = try? Data(contentsOf: assetURL) else { return nil }
203+
return try? UIImage(data: assetData)?.saveAsJpgToTemporaryUrl()
204+
}
196205
}

Sources/StreamChatSwiftUI/Utils/Common/UIImage+Extensions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ extension UIImage {
4242
}
4343

4444
extension UIImage {
45-
func temporaryLocalFileUrl() throws -> URL? {
45+
func saveAsJpgToTemporaryUrl() throws -> URL? {
4646
guard let imageData = jpegData(compressionQuality: 1.0) else { return nil }
4747
let imageName = "\(UUID().uuidString).jpg"
4848
let documentDirectory = NSTemporaryDirectory()

0 commit comments

Comments
 (0)