如何使用Photos框架获取参考URL的文件名?

时间:2016-05-30 09:36:03

标签: ios swift photosframework

这是我获得pd.DataFrame(sur_perimetre[col].value_counts()).reset_index()[:5] 的方式:

NSURL

正在使用func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) { if let referenceUrl = info[UIImagePickerControllerReferenceURL] as? NSURL { //access the file name } }

ALAssetsLibrary

自iOS 9以来已被弃用

1 个答案:

答案 0 :(得分:2)

最简单的答案:

if let asset = PHAsset.fetchAssetsWithALAssetURLs([referenceUrl], options: nil).firstObject as? PHAsset {

    PHImageManager.defaultManager().requestImageDataForAsset(asset, options: nil, resultHandler: { _, _, _, info in

        if let fileName = (info?["PHImageFileURLKey"] as? NSURL)?.lastPathComponent { 
            //do sth with file name
        }
    })
}