Decoding LPLinkMetadata loses imageProvider

Viewed 34

I have a website which I'm attempting to fetch metadata from, on some occasions the imageProvider is nil, but I have other info about that page which I can use to generate a UIImage. I wish to cache the resultant LPLinkMetadata after I replace the imageProvider with my own, but I find even the most simple scenarios, encoding the imageProvider is seemingly impossible.

let metadata = LPLinkMetadata()
metadata.imageProvider = NSItemProvider(object: UIImage())
metadata.title = "Test"
print(metadata.imageProvider) //Prints a valid NSItemProvider
print(metadata.title) //Prints "Test"

//Encode it, then decode it
let encodedMetadata = try! NSKeyedArchiver.archivedData(withRootObject: metadata, requiringSecureCoding: false)
let decodedMetadata = try! NSKeyedUnarchiver.unarchivedObject(ofClass: LPLinkMetadata.self, from: encodedMetadata)

print(decodedMetadata?.imageProvider) //Prints nil
print(decodedMetadata?.title) //Prints "Test"

How can I encode the LPLinkMetadata and preserve the image I attach to it?

0 Answers
Related