diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 5a6faae..fdea2cf 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -233,7 +233,7 @@ PODS: - React-cxxreact (= 0.62.2) - React-jsi (= 0.62.2) - React-jsinspector (0.62.2) - - react-native-image-selector (0.1.14): + - react-native-image-selector (0.1.15): - React - React-RCTActionSheet (0.62.2): - React-Core/RCTActionSheetHeaders (= 0.62.2) @@ -429,7 +429,7 @@ SPEC CHECKSUMS: React-jsi: b6dc94a6a12ff98e8877287a0b7620d365201161 React-jsiexecutor: 1540d1c01bb493ae3124ed83351b1b6a155db7da React-jsinspector: 512e560d0e985d0e8c479a54a4e5c147a9c83493 - react-native-image-selector: 196e21b2c85ee4a59f36bb1e9e8d11a0b8a601b4 + react-native-image-selector: 0d24ac8a6cae3e58f5e793b57d607161d98beed1 React-RCTActionSheet: f41ea8a811aac770e0cc6e0ad6b270c644ea8b7c React-RCTAnimation: 49ab98b1c1ff4445148b72a3d61554138565bad0 React-RCTBlob: a332773f0ebc413a0ce85942a55b064471587a71 diff --git a/ios/ImageSelector.swift b/ios/ImageSelector.swift index 22c1553..e1e0733 100644 --- a/ios/ImageSelector.swift +++ b/ios/ImageSelector.swift @@ -244,7 +244,7 @@ extension ImageSelector: UIImagePickerControllerDelegate { case .camera: if let pickedImage = info[UIImagePickerController.InfoKey.originalImage] as? UIImage { if let rotatedImage = ImageUtil.rotateImage(image: pickedImage) { - if let imageData = rotatedImage.pngData() { + if let imageData = rotatedImage.jpegData(compressionQuality: 1.0) { var pathDirectory: String? = nil if let storageOptions = self.options["storageOptions"] as? [String: Any] { if let path = storageOptions["path"] as? String { diff --git a/ios/ImageUtil.swift b/ios/ImageUtil.swift index e33839b..f6383b9 100644 --- a/ios/ImageUtil.swift +++ b/ios/ImageUtil.swift @@ -11,6 +11,14 @@ import Photos class ImageUtil: NSObject { static func createCacheFile(imageData: Data, pathDirectory: String?, callback: RCTResponseSenderBlock?) -> [String: Any]? { + guard let jpegImage = UIImage(data: imageData) else { + return nil + } + + guard let imageData = jpegImage.jpegData(compressionQuality: 1.0) else { + return nil + } + let fileManager = FileManager.default if let documentDirectoryPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first { let path = (documentDirectoryPath as NSString).appendingPathComponent(pathDirectory ?? "") @@ -24,7 +32,7 @@ class ImageUtil: NSObject { return nil } let uuid: String = UUID().uuidString - let fileName = (uuid as NSString).appendingPathExtension("png") ?? "\(uuid).png" + let fileName = (uuid as NSString).appendingPathExtension("jpeg") ?? "\(uuid).jpeg" let filePath = (path as NSString).appendingPathComponent(fileName) fileManager.createFile(atPath: filePath, contents: imageData, attributes: nil) let base64EncodedString: String = imageData.base64EncodedString() @@ -33,7 +41,7 @@ class ImageUtil: NSObject { "path": filePath, "uri": "file://\(filePath)", "fileName": fileName, - "type": "image/png", + "type": "image/jpeg", "fileSize": imageData.count ] } diff --git a/package.json b/package.json index a7a1117..5f024f1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-image-selector", - "version": "0.1.14", + "version": "0.1.15", "description": "image picker native module", "main": "lib/commonjs/index", "module": "lib/module/index",