Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get a PHAsset from ReferenceURL: fetchAssets(withALAssetURLs:options:) DEPRECATED

My goal is to upload original resolution device captured video files to S3 using AWSS3TransferUtility.

User selects a video using UIImagePickerController however, if I pass info[UIImagePickerControllerMEDIAURL] to the transferUtility it always reduces the video to 720p. If I pass the transferutility info[UIImagePickerControllerREFERENCEURL] I get an Error:

The operation couldn’t be completed. (com.amazonaws.AWSS3TransferUtilityErrorDomain error 4.)

Cannot find an explanation of the error code so I am assuming it is a permissions error because I am not accessing the asset via the Photos framework or PHAsset.fetch

  • REFERNCE URL - assets-library://asset/asset.mov?id=5B99DC8E-B94E-4CBF-AFB8-7F82BC72FEE2&ext=mov

  • MEDIA URL - file:///private/var/mobile/Containers/Data/Application/76928AD7-F142-4CC9-9708-A58C8CAF8EE5/tmp/trim.82038B6A-222F-4B50-A937-A8C399B02A08.MOV

Now, I have the ReferenceURL, and am trying to get the PHAsset so that I can copy it the Documents Directory and pass the URL of it to TransferUtility from there to get around the AWSS3TransferUtilityErrorDomain error 4.

However, fetchAssets(withALAssetURLs:options:) is now deprecated so I cannot fetch the asset with the ReferenceURL; all the other methods are batch fetching via media type, etc. There is fetchAssets(withLocalIdentifiers:options:) but I am not sure how to get the local identifier of a PHAsset just from the URL.

like image 440
T Rogers Avatar asked Nov 22 '17 13:11

T Rogers


1 Answers

If you need PHAsset of selected item, you can get it directly from info in UIImagePickerController callback

let asset = info[.phAsset] as? PHAsset

if it is not there, then you did not request authorization before using picker, so do this

let status = PHPhotoLibrary.authorizationStatus()

if status == .notDetermined  {
    PHPhotoLibrary.requestAuthorization({status in

    })
}

Note: localIdentifier is a property of PHObject, and PHAsset is a subclass of PHObject.

like image 190
Asperi Avatar answered Oct 31 '22 07:10

Asperi