PHObject localIdentifier not persistent between backup restores

I'm working on an app that uses photos (including Live Photos) from the users Photo Library. I'm currently storing the localIdentifier in CoreData and everything is working great. However I wanted to see if the database was persistent when the user restored from an iCloud backup. The database is intact, however all calls to fetchAssets return no items.


let options = PHFetchOptions()
options.includeAllBurstAssets = false
options.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)]
options.fetchLimit = identifiers.count
        
let assetResult = PHAsset.fetchAssets(withLocalIdentifiers: identifiers, options: options)
var assetArray:[PHAsset] = []
for i in 0..    let asset = assetResult[i]
    assetArray.append(asset)
}


Am I missing something or is there a more persistent way of referencing photos in the users Photo Liibrary?


I am also concerend some people claim it can change between OS updates.

Replies

Hey Chris, did you ever work out a solution to this?


Thanks!

I didn't find any solution to get an persistent identifier, so I resorted to some kind of "CreationDate + size (+movie length)" based identifer.

Note: Some of the images in my library seem to be missing an creation date.

Well, my use case is also knd of different - I need to match (iCloud synced) assets between iOS and macOS devices to match metadata.

Use

PHCloudIdentifier
everywhere.


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

Any idea how to get the cloudIdentifier from an MLMediaObject (the opaque wrapper for an PHAsset) on macOS?