2

I have created this Share Button that has items to share like an URL and a Text.

When i hit the Share Button though it only shows the Text to share but not the URL.

How does one select precedence of the URL over the text? Such that when sharing to Facebook it only takes the URL, but when posting to Twitter it uses the URL as well as the Text ?

import SwiftUI

struct ShareButton: View {
    @State private var isShareSheetShowing = false
    var url : String = "https://apple.com"
    
    var body: some View {
        Button(action: shareButton){
            Image(systemName: "square.and.arrow.up")
                .frame(width: 35, height: 35)
        }
    }
    
    
    func shareButton() {
        isShareSheetShowing.toggle()
        let items: [Any] = [URL(string: url)!, "Visit the Apple Website Text"]
        
        let av = UIActivityViewController(activityItems: items, applicationActivities: nil)
        
        UIApplication.shared.windows.first?.rootViewController!.present(av, animated: true, completion: nil)
    }
    
}

struct ShareButton_Previews: PreviewProvider {
    static var previews: some View {
        ShareButton()
    }
}
AndiAna
  • 854
  • 6
  • 26

1 Answers1

1

I'm also looking for an approach with directly sharing to Facebook for SwiftUI.

My problem is how to wrap the following function (from Facebook iOS SDK) within a SwiftUI view

let content = ShareLinkContent()
        content.contentURL = url
ShareDialog(
            fromViewController: self,
            content: content,
            delegate: self
        )
StupidWolf
  • 45,075
  • 17
  • 40
  • 72