简体   繁体   中英

How to attach a short data to a photo in iOS/macOS cloud shared album?

I am building an app that shares photos between iOS/macOS users through the cloud shared album of the Photos application. I need each photo to be described by a few numbers carrying app-specific parameters.

I was researching through several ideas, none of which worked:

  1. Writing numbers (or strings) into EXIF or IPTC meta-data fields

    • unfortunately, Apple cloud shared albums do not carry meta-data fields writable by a user
  2. Inserting numbers into the photo filename eg IMG_1234-i1-i2-...-iN.JPEG

    • unfortunately, I can't find a way to change the filename of a photo in the Photos app.
  3. Saving integers parallelly in an iCloud along with a photo identifier, so data can be retrieved on each device using the photo identifier

    • I assume that PHObject.localIdentifier is not persistent across the cloud shared albums read on different devices. I did not check this, but why otherwise the identifier would be called local ?

Is there any working way to bind a small amount of data to the photo in Cloud Shared Album of iOS/macOS Photos app ?

Following a description of a private API which I found in this answer I created the following extension to PHAsset:

extension PHAsset {
    var cloudIdentifier: String {
        return (self.value(forKey: "cloudIdentifier") as? String) ?? "?"
    }
}

The cloudIdentifier which you can get now from a PHAsset instance is persistent throughout the cloud on any devices sharing the same album. With persistent PHAsset identifier, one can implement solution #3 from the initial question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM