6

Are there ever circumstances where the localIdentifier could change or not be accurate? I'm working on an application that backs up photos and have been told by my colleagues that the localIdentifier can't be trusted. However, after doing some research I have been unable to find anyone talking about this.

Richmond Watkins
  • 1,342
  • 9
  • 17
  • Read this, it may helps: http://stackoverflow.com/questions/34237013/how-to-find-identifier-of-a-photo-asset-in-ios – Jamshed Alam Oct 17 '16 at 20:11

2 Answers2

4

LocalIdentifiers sometimes change after updating the iOS version.

I've seen the PHAsset.localIdentifiers (Photo API) change after iOS updates twice - in my own Apps. The last time was after updating to iOS 11. The app in question kept track of localIdentifiers so specific images could be found/sorted according to various predicates.

As soon as the update from iOS10 to 11 finished, all the localIdentifiers saved locally by the app became useless as they didn't match any device images, although they still existed in the camera roll.

Like you I've searched for info on this subject without success. Sorry that my reply is bad news.

otaviokz
  • 127
  • 5
  • 2
    localIdentifiers never changing on device. My app #pictagger is in appstore since 2015, no changes on localidentifier since then. – kurtanamo Jan 03 '20 at 11:54
4

Use PHCloudIdentifier everywhere. You can use myCloudIdentifier.stringValue if you need it for data storage purposes.

Use cloudIdentifiers(forLocalIdentifiers:) method to convert from local to cloud and the sister method, localIdentifiers(for: [PHCloudIdentifier]), to convert back again.

Stickley
  • 4,561
  • 3
  • 30
  • 29
  • 1
    This API only exists on Mac, not on iOS. – stonemonk May 17 '20 at 10:00
  • 1
    How does this work for iOS then? Local identifiers don't seem to be stable across two devices of the same user having the same iCloud media library - how do you detect the semantic ID representing the same photo within the user's media library across two devices? (ie: an iPhone and an iPad) – Marchy Jun 12 '20 at 22:43