2

iOS15 has a new shared with you feature on apple's apps- safari, apple news, music, movies, etc. For example, if any of my friends share the news link from apple news to me on apple messages, when I open the Apple news and scroll to the home page I get a section for 'shared with you' articles. It also shows the name of the friend how shared it with me.

I am wondering is there any API/source I can use to provide the same experience on my app? I found https://developer.apple.com/videos/play/wwdc2021/10187/, but this video doesn't explain the 'shared with you' implementation. Please share ideas for the implementation. Thanks in advance.

adee
  • 77
  • 8

2 Answers2

1

With iOS 16 it will be possible to implement Shared with You support for your app.

Check out this WWDC22 Session Add Shared with You to your app.

Witek Bobrowski
  • 3,749
  • 1
  • 20
  • 34
1

Well I spent a bunch of time on implementing Shared With You for iOS 16. There is not much information available beyond the WWDC video listed in the previous answer. But, I did get it working. Here was my approach.

  1. Make sure your device is running at least iOS 16.0.3. It didn't start working until I installed this version and did the rest of the following.

  2. Follow these instructions: https://www.avanderlee.com/swift/shared-with-you/

  3. When implementing Universal Links, you just have to return true (in your app delegate) once you recognize the universal link as one of the links from Messages that contain Shared With You content. You do NOT need to implement SWCollaborationMetaData. It is kinda implied in the Apple docs that you might need to do this but you do not.

  4. In the SharedWithYouMonitor (as referenced in item 2 above), set up a array that can hold all of your hightlights. You will need this array in the view that displays the Shared With You content. Append each hightlight to the array in the delegate method highlightCenterHighlightsDidChange...

    @Published var sharedItems = [SharedWithYouModel]()
    
  5. I set up a simple model for the hightlights. Something like:

     import Foundation
     import SharedWithYou
    
     @available(iOS 16.0, *)
     struct SharedWithYouModel: Identifiable {
       var id = UUID()
       let swHighlight: SWHighlight
       let url: URL
     }
    
  6. In your view where you will show the SharedWithYou content, mark it as:

    @available(iOS 16.0, *)
    struct SharedWithYou: View {
      @Environment(\.horizontalSizeClass) var sizeClass
      @StateObject var monitor = SharedWithYouMonitor()
      var gridItemLayout = [GridItem(.adaptive(minimum: 100, maximum: 150), spacing: 30)]
    
    var body: some View {
     ZStack {
       ScrollView {
        Text("ContentOne") 
         .foregroundColor(Color(hex: 0x0DB9D6))
        LazyVGrid(columns: gridItemLayout, spacing: horizontalSpace) {
         ForEach(monitor.sharedItems) { item in
           SharedWithYouView(.........
    
  7. Other: I used the SWAttributionView suggested in 2. Make sure your users have Shared With You on for your app in Settings--Messages--Shared With You. You can send content to yourself in Messages to test. It seems that content received in Messages will only show if the recipient pins the content in Messages and/or the recipient has the sender as a contact in their Contacts. I guess this is for privacy control.

D. Rothschild
  • 659
  • 9
  • 14