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"]
                        }
                    }
                }
            }
        })
    }


Post not yet marked as solved Up vote post of sorth Down vote post of sorth
3.3k views

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

I have the same problem mentioned in this thread. I have been able to access the title metadata using asset.value(forKey: "title") as? String, where asset is a PHasset retreived from a photo library. However, as far as I can tell there is no property key for the "caption" metadata.

Hello,

There is no API or supported way to read or edit that caption. That being said, I encourage each of you to file an enhancement request with details about your intended use-cases for reading and/or writing that caption using Feedback Asstant.

Add a Comment

Has there been any progress on this? When I follow the link to that enhancement request posted by 262Hz I just get a page that says "Feedback not found"

@gchiste Any update on this?

@fivestones I filed an "enhancement request" using the "Feedback Assistant" as suggested, but the link is apparently useless for sharing publicly.