0

I'm trying to convert from ALAssetsLibrary to PHPhotoLibrary since it is deprecated. I need to grab the date from a chosen photo from the photo library but can't figure out the right way. Here is how I'm currently doing it.

mediaUrl = info[UIImagePickerControllerReferenceURL] as? NSURL

...

let assetsLibrary = ALAssetsLibrary()
assetsLibrary.assetForURL(mediaUrl, resultBlock: { (asset) -> Void in
    guard let asset = asset else { return }
    guard let date = asset.valueForProperty(ALAssetPropertyDate) as? NSDate else { return }
    let dateString = dateFormatter.stringFromDate(date)

    //---- use date string here

    }) { (error) -> Void in
        print(error)
    }

Here is where I've gotten to:

let photoLibrary = PHPhotoLibrary.sharedPhotoLibrary()
var photoAssetPlaceholder: PHObjectPlaceholder!
photoLibrary.performChanges({
    let request = PHAssetChangeRequest.creationRequestForAssetFromImage(image)
    photoAssetPlaceholder = request.placeholderForCreatedAsset
    }, completionHandler: { success, error in
        if success {
            print (photoAssetPlaceholder)
            //How do I get date from PhotoAssetPlaceholder???
        } else {
            print(error?.localizedDescription)
        }

        })

I feel like I'm close. Any help would be appreciated!

Jeremiah
  • 1,471
  • 1
  • 13
  • 22

1 Answers1

0

The model objects that represents the photos and videos themselves are of type PHAsset.

A PHAsset contains metadata such as the asset’s media type and its creation date.

enter image description here

Shamsudheen TK
  • 30,739
  • 9
  • 69
  • 102