I'm seeing the same issue but on iOS (iOS 14 beta 5). Here's the code I'm currently testing with, found it somewhere on the interwebz so I take no credit for it.
import SwiftUI
struct ShareSheetView: 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 ShareSheetView_Previews: PreviewProvider {
static var previews: some View {
ShareSheetView(activityItems: [URL(string: "https://volante.io")!])
}
}
* Edit:
I just noticed that the ivar activityItems is an array of Any, which let me send a URL wrapped in a Binding<>. This is of course not share:able and this is the reason I was seeing this bug.
Maybe this is the same error you've made? To get it working I updated the code to this:
ShareSheetView(activityItems: [self.filePath.unsafelyUnwrapped])
I use unsafelyUnwrapped because I know the filePath property will always be set.
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: