I'm currently facing a problem where both the title and thumbnail of UIActivityViewController are not being displayed when I use this controller in my current project. On the other hand, the same code results in the title and thumbnail displaying correctly when applied to a different project. The sharing functionality is working as expected - the link is shared properly - but the title and thumbnail simply do not show up. My current environment involves using SwiftUI view through UIHostingController.
Here is the code snippet:
Button {
viewModel.link = URL(string:"https://www.apple.com")
isSharePresented = true
} label: {
Image("ic-share-top-\(isHeaderVisible ? "black" : "white")-40")
}
.font(.system(size: 18.toPt(), weight: .bold))
.foregroundColor(isHeaderVisible ? .black : .white)
.frame(width: 40.toPt(), height: 40.toPt())
.sheet(isPresented: $isSharePresented) {
if let url = viewModel.link {
ActivityViewController(
activityItems: [url],
applicationActivities: nil
)
}
}
struct ActivityViewController: UIViewControllerRepresentable {
var activityItems: [Any]
var applicationActivities: [UIActivity]?
@Environment(\.presentationMode) var presentationMode
func makeUIViewController(context: UIViewControllerRepresentableContext<ActivityViewController>
) -> UIActivityViewController {
let controller = UIActivityViewController(
activityItems: activityItems,
applicationActivities: applicationActivities
)
controller.completionWithItemsHandler = { (_, _, _, _) in
self.presentationMode.wrappedValue.dismiss()
}
return controller
}
func updateUIViewController(
_ uiViewController: UIActivityViewController,
context: UIViewControllerRepresentableContext<ActivityViewController>
) {}
}
Could anyone shed some light on why the title and thumbnail are not appearing and how to correct this issue? Your assistance would be greatly appreciated!