Open giofid opened 5 years ago
Hi, @giofid You right. It was bug, i've fixed that and push now. https://github.com/tilltue/TLPhotoPicker/commit/e1ea38e1389094bcffc830c5a4a3afecfab48b13
Hi, @tilltue
In my app I'm implementing a function like tempCopyMediaFile()
to copy an image/video from photo library into Documents
app folder. I'm a little confused about Photos
framework so I take this opportunity to ask you if it's possible to use PHAssetResourceManager.default().requestData()
or PHAssetResourceManager.default().writeData()
regardless to PHAssetResourceType
. At line 190 you already have the right asset resource. Why can't you just use that to request or write its data?
....
guard let resource = (PHAssetResource.assetResources(for: phAsset).filter { $0.type == type }).first else { }
let fileName = resource.originalFilename
let options = PHAssetResourceRequestOptions()
options.isNetworkAccessAllowed = true
var imageData = Data()
PHAssetResourceManager.default().requestData(for: resource, options: options, dataReceivedHandler: { (data) in
imageData.append(data)
}, completionHandler: { (error) in
DispatchQueue.main.async {
if error != nil {
// show error message
} else {
// write imageData to fileName file into Documents folder
}
}
})
.....
Thanks for your help.
Hi, @giofid As you know, If the asset is 'icloud photos', you need to download it.
You right. There are options for download in 'PHAssetResourceManager.default().writeData' ( isNewtorkAccessAllowed in 'PHAssetResourceRequestOptions')
It's not much different than writeData after requestLivePhoto.
But I wanted to provide more contextual options. That's why it using 'PHImageManager.default().requestLivePhoto' functions. ( isNetworkAccessAllowed options in PHLivePhotoRequestOptions )
It was a function provided for convenience, so I thought it would be good to have more useful.
Thank you @tilltue, @wade-hawk!! I take advantage of your help to submit you two other things:
originalFilename
will be something.PNG, but uti
string returned by PHImageManager.default().requestImageData()
is a jpeg. So the right name should be something.jpeg.info
parameter of
open func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any])
we can obtain info[. imageURL]
, and in that URL there's a jpg version of the HEIC file and its size is bigger than HEIC file. I'm a little confused!!PNG Case
HEIC Case
JPEG Case
@giofid I can't understand why should renamed file in this function? I think if you need to convert png to jpg should making custom functions.
Hi @tilltue, to reproduce the extension mismatch you have to edit a png image into your Photo Library.
During this test you'll also see that computed var originalFileName
implementation is not entirely correct. With edited photo, in the first position of PHAssetResource.assetResources()
array you'll find an Adjustment.plist
file
public var originalFileName: String? {
get {
guard let phAsset = self.phAsset,let resource = PHAssetResource.assetResources(for: phAsset).first else { return nil }
return resource.originalFilename
}
}
A similar issue happens if you try to export a non-live HEIC photo - the resulting file has a JPG extension but the file itself is still HEIC. Of course, it's not a problem for live photos if convertLivePhotosToJPG
is true
.
I am not sure that
tempCopyMediaFile()
function is entirely correct when the asset is a live photo andconvertLivePhotosToJPG
isfalse
. In this case we obtain a .MOV file but the content ofdata
(returned byPHImageManager.default().requestImageData()
) is a jpeg. So we 'll get a video that's not a video.