iOS8 Photos Framework: How to get the name(or filename) of a PHAsset?

后端 未结 7 1190
野趣味
野趣味 2020-11-28 10:06

Im trying to get the image name using PHAssets. But I couldn\'t find metadata for filename or any method to get the image name. Is there a different way to get

7条回答
  •  臣服心动
    2020-11-28 10:26

    I know the question has already been answered, but I figured I would provide another option:

    extension PHAsset {
    
        var originalFilename: String? {
    
            var fname:String?
    
            if #available(iOS 9.0, *) {
                let resources = PHAssetResource.assetResources(for: self)
                if let resource = resources.first {
                    fname = resource.originalFilename
                }
            }
    
            if fname == nil {
                // this is an undocumented workaround that works as of iOS 9.1
                fname = self.value(forKey: "filename") as? String
            }
    
            return fname
        }
    }
    

提交回复
热议问题