Sharing to Instagram using UIActivityView in SwiftUI

Viewed 619

Im trying to share a Instagram post from an app that I made in swiftUI using UIActivityView, but whenever I try to share it only the picture shows up and the caption doesn't. The same thing happens with Facebook.

func sharePost(){
        isSheetShowing.toggle()
        let caption = "Hello, world!"

        if let image = UIImage(named: "Image") {

            let vc = UIActivityViewController(activityItems: [image,caption], applicationActivities: nil)

            UIApplication.shared.windows.first?.rootViewController?.present(vc,animated : true)
        }
    }
1 Answers

UIActivityController needs to correctly recognize what exactly you are trying to share in order to display it corrrectly. This solution seems to answer your question directly.

Also, this is kind of an anti-pattern in SwiftUI (presenting it directly on the window). You should check this question out.

Related