Display Shared Links with SharedWithYou in iOS 16
In iOS 16, Apple's SharedWithYou framework allows developers to
present web links and universal links sent through Messages directly
inside their own native apps. By leveraging the framework's dedicated
APIs—specifically SWHighlightCenter and
SWAttributionView—apps can surface shared content alongside
contextual sender information, enabling users to view the content and
reply back into Messages without leaving the app.
Detecting Shared Content with SWHighlightCenter
The integration begins with SWHighlightCenter, the
central coordinator that tracks incoming links and media shared with the
user. When an app launches, it initializes an instance of
SWHighlightCenter and assigns a delegate conforming to
SWHighlightCenterDelegate.
Whenever a contact shares a Universal Link belonging to the app in
Messages, iOS flags the link as a highlight. The framework posts updates
through the delegate method
highlightCenterHighlightsDidChange(_:). The app queries the
highlight center's highlights array, filtering for
SWURLHighlight objects. Each SWURLHighlight
contains the destination URL that matches the app's supported
content.
Presenting Sender Attribution with SWAttributionView
To display the social context of a link, iOS 16 relies on
SWAttributionView. Developers do not manually design or
render the sender's contact details; instead, Apple provides this
standardized, system-rendered view to maintain visual consistency and
protect user privacy.
The process for displaying the attribution includes:
- Instantiation: Create an instance of
SWAttributionViewand add it to the view hierarchy alongside the content preview (such as a card, collection view cell, or banner). - Assignment: Assign the corresponding
SWURLHighlightobject to thehighlightproperty of theSWAttributionView. - Layout: Position the attribution view. It automatically adjusts its dimensions to present a pill-shaped indicator displaying the sender's avatar and name.
Privacy and Interaction Handling
SWAttributionView runs as a secure out-of-process UI
element. The host app never gains direct access to the sender’s personal
information, contact photo, or the message thread itself.
When a user taps the SWAttributionView:
- A system-level menu appears, displaying the original message snippet and conversation details.
- The user can send a quick inline reply back into the Messages conversation.
- The user can jump directly into the full conversation in the Messages app.
By linking SWURLHighlight to
SWAttributionView, apps in iOS 16 integrate shared web
links natively while delegating privacy-sensitive interaction to the
operating system.