Learn iOS Development

Boost Your Shared Content in iOS with ShareWithYou Framework

Aid Your Users In Retrieving Content that May Have Been Misplaced Within A Message Chat

Shashank Thakur
Mobile App Development Publication

--

How to boost your shared content in iOS with ShareWithYou Framework

Integrate ShareWithYou Framework

The SharedWithYou framework is a new feature introduced by Apple with iOS 16 that allows apps to share content with the user through the system-level SharedWithYou experience. This feature makes it easier for users to discover and access shared content from apps such as Messages, Photos, and Safari. In this blog post, we will closely examine the SharedWithYou framework and how it can benefit app developers.

What is the SharedWithYou Framework?

The SharedWithYou framework is a new feature introduced by Apple in iOS 16. It allows apps to share content such as articles, music, podcasts, photos, and videos directly with the user through the SharedWithYou experience. When a user receives shared content, the SharedWithYou experience displays a preview of the content and provides quick access to the app that shared it.

How does SharedWithYou Works?

With the Shared with You system, you can enhance the content that has been shared through Messages within your app. This enables users to keep messaging without having to exit the app. When someone shares content, you will receive a SWHighlight item which can be linked to a SWAttributionView. This will display information about the conversation in which the content was shared. Users can click on the attribution view to be taken back to the conversation through a deep link.

When do we see share with you content?

Users have control over the content displayed in Shared with You, including the ability to pin and prioritize certain items. If users pin content, it will be highlighted in Shared with You alongside any content suggested by Siri. Users can also choose to disable content sharing on a per-conversation basis through chat settings. Additionally, the Messages system settings provide options for disabling automatic sharing globally or for specific apps. Below is a screenshot of the shared setting on your iOS device.

Integrate the SharedWithYou Framework in our application

Adding ShareWithYou functionality in our app is pretty straightforward. Please follow the steps mentioned below

  1. Add Universal Link Support

Universal links facilitate users to open content directly within your app. In case you haven’t added universal links to your app yet, please refer to apple documentation here.

2. Add SharedWithYou framework as a capability in our app capabilities

3. Integrate the framework into the app

import UIKit
import SharedWithYou
class ShareWithYouViewController: UIViewController {
let hightLightCenter = SWHighlightCenter()
override func viewDidLoad() {
super.viewDidLoad()
hightLightCenter.delegate = self
}

}
extension ShareWithYouViewController: SWHighlightCenterDelegate {
func highlightCenterHighlightsDidChange(_ highlightCenter: SWHighlightCenter) {
for highlight in highlightCenter.highlights {
let highlightUrl = highlight.url
//generate the rich preview
}
}
}

The code above is setting the view controller to display highlights of content shared with the user and will generate rich previews of these highlights when they change.

Adding SWAttributionView.

Here is an example of SWAttributionView with a basic setup.

  let attributionView = SWAttributionView()
attributionView.horizontalAlignment = .center
attributionView.displayContext = .summary
attributionView.highlight = highLight

As the next step, the user can make an instance of `SWAttributionView` and populate the highlight property as accessible above. Some other properties worth noting that you can set on SWAttributionView are background style, display context, and horizontal alignment as per your requirements. Once the SWAttributionView is populated as per your requirements, you can add it to your UI. The SWAttributionView serves as a holder for the Messages ‘pill’, which enables users to deep link back to the conversation related to the content.

Things to keep in mind

  1. Make sure ShareWithYou capability is added and SWHighlightCenterDelegate is implemented
  2. Highlight won’t work on the simulator, please use a physical device for this.
  3. Only things that were shared by contact from the contact list would appear in the highlights of your `highlightCenterHighlightsDidChange` method.
  4. Make sure you turn on the global sharing setting and your app-specific setting.

Conclusion

Incorporating “Shared with You” into your app aids your users in retrieving content that may have been misplaced within a Messages chat.

--

--