Creation Date from Camera Roll Image

吃可爱长大的小学妹 提交于 2019-12-08 12:46:25
chrisco

based on Your code and How can I get image created date time or last modified date time from iOS Photos (like camera roll)?

this one works for me on XCode 6.1.1 for Swift:

func imagePickerController(picker: UIImagePickerController!, didFinishPickingMediaWithInfo info:NSDictionary!) {

    let library = ALAssetsLibrary()
    var url: NSURL = info.objectForKey(UIImagePickerControllerReferenceURL) as NSURL

    library.assetForURL(url, resultBlock: {
        (asset: ALAsset!) in
        if asset != nil {

        //print the creation date
        println(asset.valueForProperty(ALAssetPropertyDate))

        }
        }, failureBlock: {
            (error: NSError!) in

            NSLog("Error!")
        }
    )}

Found the solution myself:

            var image_representation : ALAssetRepresentation = asset.defaultRepresentation()

            var iref : CGImage = image_representation.fullResolutionImage().takeUnretainedValue()

            var metaData : NSDictionary = image_representation.metadata()

here swift 3 code for checking creation date

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
    let library = ALAssetsLibrary()
    let url: NSURL = info[UIImagePickerControllerReferenceURL] as! NSURL
    library.asset(for: url as URL, resultBlock: { (asset: ALAsset?) in
        if asset != nil {
            //print the creation date
            print(asset!.value(forProperty: ALAssetPropertyDate))
        }
    }, failureBlock: { (error: Error?) in
        NSLog("Error \(error)")
    })
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!