Skip to content

Instantly share code, notes, and snippets.

@colinfwren
Created January 10, 2025 22:14
Show Gist options
  • Save colinfwren/ae50f598a142f59a153d7ac44256c87b to your computer and use it in GitHub Desktop.
Save colinfwren/ae50f598a142f59a153d7ac44256c87b to your computer and use it in GitHub Desktop.
Share Sheet wrapping of UIActivityViewController
import SwiftUI
import UIKit
import OSLog
let shareSheetLogger = Logger(subsystem: "", category: "view.ShareSheet")
struct ShareSheet: UIViewControllerRepresentable {
typealias UIViewControllerType = UIActivityViewController
@Binding var showing: Bool
var sharing: [Any]
func makeUIViewController(context: UIViewControllerRepresentableContext<ShareSheet>) -> UIActivityViewController {
let vc = UIActivityViewController(activityItems: sharing, applicationActivities: nil)
vc.completionWithItemsHandler = { activityType, completed, items, error in
if (error != nil) {
shareSheetLogger.error("Error sharing: \(error!.localizedDescription)")
}
if (completed) {
shareSheetLogger.info("Completed sharing")
} else {
shareSheetLogger.info("Dismissed sharing")
}
self.showing = false
}
return vc
}
func updateUIViewController(_ uiViewController: UIActivityViewController, context: UIViewControllerRepresentableContext<ShareSheet>) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment