iOS照片库-如何获取REAL文件名?

时间:2019-03-27 19:46:12

标签: ios swift phasset

我正在为此寻找Swift或Objective C解决方案。在这里,我展示了使用swift的示例。

我在iOS上使用Photos框架,很难找到REAL文件名而不是IMG_4227.JPG类型。我的图像名称实际上是myawesomefilename.jpg,如果我从iPhone空投或转移到保管箱图像,我会看到此文件名。但是当我使用Photos框架时,我得到的名称为IMG_4227.JPG

应用程序商店中有一个应用程序可以获取所有图像的真实文件名,因此绝对有可能。我就是不知道。

这是我目前获得的IMG_4227.JPG类型名称的方式:

func exifTapped(asset: PHAsset) {
        print("name: \(asset.value(forKey: "filename"))")

        getURL(ofPhotoWith: asset) { (url) in
            print("URL: \(url)")
            let data = NSData.init(contentsOf: url!)!
            if let imageSource = CGImageSourceCreateWithData(data, nil) {
                let imageProperties2 = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, nil)! as NSDictionary
                print("imageProperties2: ", imageProperties2)
            }
        }
    }


    func getURL(ofPhotoWith mPhasset: PHAsset, completionHandler : @escaping ((_ responseURL : URL?) -> Void)) {

        if mPhasset.mediaType == .image {
            let options: PHContentEditingInputRequestOptions = PHContentEditingInputRequestOptions()
            options.isNetworkAccessAllowed = true
            options.canHandleAdjustmentData = {(adjustmeta: PHAdjustmentData) -> Bool in
                return true
            }
            mPhasset.requestContentEditingInput(with: options, completionHandler: { (contentEditingInput, info) in
                completionHandler(contentEditingInput!.fullSizeImageURL)
            })
        } else if mPhasset.mediaType == .video {
            let options: PHVideoRequestOptions = PHVideoRequestOptions()
            options.version = .original
            options.isNetworkAccessAllowed = true
            PHImageManager.default().requestAVAsset(forVideo: mPhasset, options: options, resultHandler: { (asset, audioMix, info) in
                if let urlAsset = asset as? AVURLAsset {
                    let localVideoUrl = urlAsset.url
                    completionHandler(localVideoUrl)
                } else {
                    completionHandler(nil)
                }
            })
        }

    }

编辑:没有重复的解决方案,与我已有的解决方案没有什么不同,它们都给出了IMG_4227.JPG类型的名称,而不是真实名称。所以这不是重复的。

1 个答案:

答案 0 :(得分:0)

我知道了。

diag
相关问题