gpt4 book ai didi

iOS 照片库 - 如何获取真实的文件名?

转载 作者:行者123 更新时间:2023-11-29 05:53:56 25 4
gpt4 key购买 nike

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

我在 iOS 上使用照片框架,但很难找到真实的文件名而不是 IMG_4227.JPG 类型。我的图像的名称实际上是 myawesomefilename.jpg,如果我将图像从 iPhone 空投或传输到保管箱,我会看到此文件名。但是当我使用照片框架时,我得到的名称为 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 类型名称而不是真实名称。所以这不是重复的。

最佳答案

我明白了。

let resources = PHAssetResource.assetResources(for: asset)
print("Filename: \((resources.first as! PHAssetResource).originalFilename)")

关于iOS 照片库 - 如何获取真实的文件名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55385350/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com