Leonardo Amigoni
Leonardo Amigoni

Reputation: 2327

ALAsset Unique identifier

I want to duplicate an image from the Photo Library but I want to check in the future if I already have imported this image.

Immagine this scenario.

  1. I have a photo in my Photo Library.
  2. I import it in my app by making a copy of it.
  3. I remove this photo from my library.
  4. At a later time I reinsert this picture to my photo library (Same photo from iPhoto, just didn't synch it's album before and I have now)

Is there a unique identifier that I can use to compare the two pictures? is the URL unique? Or do I have to look into the metadata and try to match it? If so, what would you suggest? Created Data and location? Just created Date? Size?

Thanks for your advice.

Upvotes: 4

Views: 2277

Answers (1)

groomsy
groomsy

Reputation: 4955

Observations

I've been working with similar functionality, so this is what I know:

  • Each photo inserted into the photo library will have a unique URL (this means if you insert an image, delete it, then insert it again, even if it is the same image, it will have a new URL).
  • There is no straight forward way of knowing whether an image is a duplicate of a previous image or not.
  • I don't think you are trying to do this, but I will warn you that you cannot delete an image programmatically from the iPhone Photo library.

Solutions

I really only have one way of handling this: Create a hash of the photo and store the hash somewhere. If the photo inserted is the exact same photo as before, it should give you the same hash. You can use that hash comparison to determine if you are using the same photo or not. This is the method that I am using and it seems to work reliably for the most part. I have noticed some discrepancies, but these usually involve my work hashing the files before they are added to the photo library (I have noticed that the saved photo can be different from the photo that is being saved).

I hope this information helps. Let me know if I've missed anything or you notice different results in your work.

Upvotes: 3

Related Questions