Link Presentation in iOS 13
Add metadata to your links
Difficulty: Easy | Medium | Hard
When Apple released iOS 10, Apple’s Messages app was updated to a new version that supports rich links in Messages. With iOS 13, Apple supports the use of rich links in our own apps. Here are some steps to help you implement add metadata to your links.
Step 1. Get Your Metadata
The first thing you need to create a rich link preview is
LPLinkMetadata is an object that stores metadata about the URL, including the link’s title, icon, image, and video.
Fetch metadata automatically
Because you don’t have metadata for a link, you must have another process to fetch it. For that, we can use
LPMetadataProvider is an object that retrieves metadata for a URL. After it finishes fetching, it will map the metadata to the
LPMetadataProvider supports a function is called
Below is an example.
If your link doesn’t support metadata or you want to change to another URL, title, icon, image, or video, just create
LPLinkMetadata and input the necessary data.
Below is an example for Title (title of the link).
Step 2. Create a View That Contains LPLinkMetadata
After you have
LPLinkMetadata, the next step is to create a view and put metadata into it. It’s called
LPLinkView is a rich visual representation of a link.
For ease, I want to grab all the necessary functions in one file:
Here’s the result for two cases: automatically (left) and custom (right).
Try It With Video
Implementing video is the same as implementing images, but please note the input video’s direct link.
Here’s the result:
Thanks for reading. I hope this article is useful to you.