diff --git a/Example/TLPhotoPicker/ViewController.swift b/Example/TLPhotoPicker/ViewController.swift index a7e0f2ee..bf83e1c7 100644 --- a/Example/TLPhotoPicker/ViewController.swift +++ b/Example/TLPhotoPicker/ViewController.swift @@ -70,7 +70,7 @@ class ViewController: UIViewController,TLPhotosPickerViewControllerDelegate { func getAsyncCopyTemporaryFile() { if let asset = self.selectedAssets.first { - asset.tempCopyMediaFile(progressBlock: { (progress) in + asset.tempCopyMediaFile(convertLivePhotosToPNG: false, progressBlock: { (progress) in print(progress) }, completionBlock: { (url, mimeType) in print(mimeType) diff --git a/README.md b/README.md index ff889ac6..b53d6663 100644 --- a/README.md +++ b/README.md @@ -160,7 +160,10 @@ public struct TLPHAsset { @discardableResult public func cloudImageDownload(progressBlock: @escaping (Double) -> Void, completionBlock:@escaping (UIImage?)-> Void ) -> PHImageRequestID? // get original media file async copy temporary media file ( photo(png,gif...etc.) and video ) -> Don't forget, You should delete temporary file. - public func tempCopyMediaFile(progressBlock:((Double) -> Void)? = nil, completionBlock:@escaping ((URL,String) -> Void)) -> PHImageRequestID? + // parmeter : convertLivePhotosToPNG + // false : If you want mov file at live photos + // true : If you want png file at live photos ( HEIC ) + public func tempCopyMediaFile(convertLivePhotosToPNG: Bool = false, progressBlock:((Double) -> Void)? = nil, completionBlock:@escaping ((URL,String) -> Void)) -> PHImageRequestID? // get original asset file name public var originalFileName: String? } diff --git a/TLPhotoPicker.podspec b/TLPhotoPicker.podspec index 138eb223..217d210f 100644 --- a/TLPhotoPicker.podspec +++ b/TLPhotoPicker.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = 'TLPhotoPicker' - s.version = '1.5.3' + s.version = '1.5.4' s.summary = 'multiple phassets picker for iOS lib. like facebook' # This description is used to generate tags and improve search results. diff --git a/TLPhotoPicker/Classes/TLAssetsCollection.swift b/TLPhotoPicker/Classes/TLAssetsCollection.swift index f7128c06..f0c415d5 100644 --- a/TLPhotoPicker/Classes/TLAssetsCollection.swift +++ b/TLPhotoPicker/Classes/TLAssetsCollection.swift @@ -137,10 +137,13 @@ public struct TLPHAsset { } @discardableResult - public func tempCopyMediaFile(progressBlock:((Double) -> Void)? = nil, completionBlock:@escaping ((URL,String) -> Void)) -> PHImageRequestID? { + //convertLivePhotosToPNG + // false : If you want mov file at live photos + // true : If you want png file at live photos ( HEIC ) + public func tempCopyMediaFile(convertLivePhotosToPNG: Bool = false, progressBlock:((Double) -> Void)? = nil, completionBlock:@escaping ((URL,String) -> Void)) -> PHImageRequestID? { guard let phAsset = self.phAsset else { return nil } var type: PHAssetResourceType? = nil - if phAsset.mediaSubtypes.contains(.photoLive) == true { + if phAsset.mediaSubtypes.contains(.photoLive) == true, convertLivePhotosToPNG == false { type = .pairedVideo }else { type = phAsset.mediaType == .video ? .video : .photo @@ -153,6 +156,12 @@ public struct TLPHAsset { } else { writeURL = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true).appendingPathComponent("\(fileName)") } + if (writeURL?.pathExtension.uppercased() == "HEIC" || writeURL?.pathExtension.uppercased() == "HEIF") && convertLivePhotosToPNG { + if let fileName2 = writeURL?.deletingPathExtension().lastPathComponent { + writeURL?.deleteLastPathComponent() + writeURL?.appendPathComponent("\(fileName2).png") + } + } guard let localURL = writeURL,let mimetype = MIMEType(writeURL) else { return nil } switch phAsset.mediaType { case .video: @@ -182,6 +191,10 @@ public struct TLPHAsset { } return PHImageManager.default().requestImageData(for: phAsset, options: options, resultHandler: { (data, uti, orientation, info) in do { + var data = data + if convertLivePhotosToPNG == true, let imgData = data, let rawImage = UIImage(data: imgData) { + data = UIImagePNGRepresentation(rawImage) + } try data?.write(to: localURL) DispatchQueue.main.async { completionBlock(localURL, mimetype)