iOS 14 Photo caption - how to access in metadata??

I use the following code to parse Photo metadata and this works well. However, I am unable to pull the new iOS 14 "caption" from this metadata (it worked in early iOS 14 betas, but has since stopped working in the GM.) Does anyone know how I can get the caption data from a PHAsset? Thanks!

Stephen

Code Block     func getMetaData(_ asset:PHAsset) {
        let options = PHContentEditingInputRequestOptions()
        options.isNetworkAccessAllowed = true
        asset.requestContentEditingInput(with: options, completionHandler: {(contentEditingInput, _) -> Void in
            if let url = contentEditingInput?.fullSizeImageURL {
                let fullImage = CIImage(contentsOf: url)
                
                // get all the metadata
                self.allPhotoMetadata = fullImage?.properties ?? [:]
                
                // {TIFF}
                if let tiffDict = self.allPhotoMetadata["{TIFF}"] as? [String:Any] {
                    if tiffDict["Make"] != nil {
                        self.cameraData[cameraKeys.make] = tiffDict["Make"]
                    }
                    if tiffDict["Model"] != nil {
                        self.cameraData[cameraKeys.model] = tiffDict["Model"]
                    }
                    if tiffDict["ImageDescription"] != nil {
                        self.imageData[imageKeys.caption] = tiffDict["ImageDescription"]
                    }
                }
                
                // {IPTC}
                if let iptcDict = self.allPhotoMetadata["{IPTC}"] as? [String:Any] {
                    // if we didn't find a caption in the TIFF dict, try to get it from IPTC data
                    // first try, Caption/Abtract, then ArtworkContentDescription
                    if self.imageData[imageKeys.caption] == nil {
                        if iptcDict["Caption/Abstract"] != nil {
                            self.imageData[imageKeys.caption] = iptcDict["ArtworkContentDescription"]
                        } else if iptcDict["ArtworkContentDescription"] != nil {
                            self.imageData[imageKeys.caption] = iptcDict["ArtworkContentDescription"]
                        }
                    }
                }
            }
        })
    }


Replies

Hi Sorth. Did u ever resolve this? I have the same question.
Would this change help you ?

if iptcDict["Caption/Abstract"] != nil {

self.imageData[imageKeys.caption] = iptcDict["Caption/Abstract"]


etc
Thanks for pointing out my typo. However, the iptcDict still doesn't have the caption data. I don't think there's a public API available to access this data.
Hi Bill. Nope. Still not possible. Let me know if you figure out a solution. Thanks!
  • Oh wow I was planning out my app just not even questioning whether this was possible. Why would they restrict that from us? What good is the whole Photos library if we can't get access to some of these details

Add a Comment

I too would like an API to access the user-defined caption on PHAsset or in its metadata please. FB8244665, FB10205012