【发布时间】:2019-03-27 19:46:11
【问题描述】:
我正在为此寻找 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 类型名称而不是真实名称。所以这不是重复的。
【问题讨论】:
-
没有一个重复的解决方案与我已有的解决方案有任何不同,它们都给出了 IMG_4227.JPG 类型名称而不是真实名称。所以这不是重复的。
-
@matt 没有一个重复的解决方案与我已有的解决方案有任何不同,它们都给出了 IMG_4227.JPG 类型名称而不是真实名称。所以这不是重复的。