Post

Replies

Boosts

Views

Activity

SwiftUI Share Sheet, how to set the subject field in an email
When I am using share sheet to share content via email; the subject of the content is blank and I don't see a way to set the subject line. I am trying to share some content using an email app, I would like to set the subject title in the email when the same time I pass my content to the email app. import SwiftUI import UIKit struct ContentView: View { @State private var showShareSheet = false var body: some View { VStack(spacing: 20) { Text("Hello World") Button(action: { self.showShareSheet = true }) { Text("Share Me").bold() } } .sheet(isPresented: $showShareSheet) { ShareSheet(activityItems: ["Hello World"]) } } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } } struct ShareSheet: UIViewControllerRepresentable { typealias Callback = (_ activityType: UIActivity.ActivityType?, _ completed: Bool, _ returnedItems: [Any]?, _ error: Error?) -> Void let activityItems: [Any] let applicationActivities: [UIActivity]? = nil let excludedActivityTypes: [UIActivity.ActivityType]? = nil let callback: Callback? = nil func makeUIViewController(context: Context) -> UIActivityViewController { let controller = UIActivityViewController( activityItems: activityItems, applicationActivities: applicationActivities) controller.excludedActivityTypes = excludedActivityTypes controller.completionWithItemsHandler = callback return controller } func updateUIViewController(_ uiViewController: UIActivityViewController, context: Context) { // nothing to do here } } struct ShareSheet_Previews: PreviewProvider { static var previews: some View { ShareSheet(activityItems: ["A string" as NSString]) } }
0
0
1.8k
Jul ’21