Contents

LPMetadataProvider

An object that retrieves metadata for a URL.

Declaration

class LPMetadataProvider

Overview

Use LPMetadataProvider to fetch metadata for a URL, including its title, icon, and image or video links. All properties on the resulting LPLinkMetadata instance are optional.

For each metadata request, create an instance of LPMetadataProvider and call startFetchingMetadata(for:completionHandler:).

In the completion handler, check the error. If your user doesn’t have a network connection, the fetch can fail. If the server doesn’t respond or is too slow, the fetch can time out. Alternatively, the app may cancel the request, or an unknown error may occur.

Otherwise, use the metadata however you want, for example, to populate the title for a table view cell.

let metadataProvider = LPMetadataProvider()
let url = URL(string: "https://www.apple.com/ipad")!

metadataProvider.startFetchingMetadata(for: url) { metadata, error in
    if error != nil {
        // The fetch failed; handle the error.
        return
    }

    // Make use of fetched metadata.
}

For more information about handling errors, see LPError.

Topics

Fetching metadata

Instance Methods

See Also

Link metadata