Class

LPMetadataProvider

An object that retrieves metadata for a URL.

Declaration

class LPMetadataProvider : NSObject

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.

Fetch Link Metadata from a URL

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 link presentation errors, see LPError.

Topics

Fetching Metadata

func cancel()

Cancels a metadata request.

var shouldFetchSubresources: Bool

A Boolean value indicating whether to download subresources specified by the metadata.

var timeout: TimeInterval

The time interval after which the request automatically fails if it hasn’t already completed.

Relationships

Inherits From

Conforms To

See Also

Link Metadata

class LPLinkMetadata

An object that contains metadata about a URL.