I am trying to get the URL for the image associated with a given URL. Using Apple's LPLinkMetadata
, I am able to get the URL's title
and description
, but I cannot figure out how to access the metadata's image URL. I have access to data.imageProvider
but I am not sure how to use it.
import LinkPresentation
final class URLHelper {
@available(iOS 13.0, *)
static func fetchURLPreview(url: URL) {
let metadataProvider = LPMetadataProvider()
metadataProvider.startFetchingMetadata(for: url) { (metadata, error) in
DispatchQueue.main.async {
if let _ = error {
// handle error
} else if let data = metadata {
let urlTitle = data.title
let urlImageUrl = data.????????
}
}
}
}
}