ios – SwiftUI Share Instagram Put up


I am making an attempt to share a submit from Instagram with swiftui, however it did not work, I did not have any issues whereas sharing a narrative, however the submit display screen does not open when sharing a submit.

I’m sharing pattern code


Button {
           InstagramSharingUtils.shareToInstagramFeed( myImage )


  static func shareToInstagramFeed(_ picture: UIImage) {
        // construct the customized URL scheme
        guard let instagramUrl = URL(string: "instagram://app") else {

        // test that Instagram might be opened
        if UIApplication.shared.canOpenURL(instagramUrl) {
            // construct the picture knowledge from the UIImage
            guard let imageData = picture.jpegData(compressionQuality: 100) else {

            // construct the file URL
            let path = (NSTemporaryDirectory() as NSString).appendingPathComponent("instagram.ig")
            let fileUrl = URL(fileURLWithPath: path)

            // write the picture knowledge to the file URL
            do {
                strive imageData.write(to: fileUrl, choices: .atomic)
            } catch {
                // couldn't write picture knowledge
            let pasteboardItem = ["": imageData]
            let pasteboardOptions = [UIPasteboard.OptionsKey.expirationDate: Date().addingTimeInterval(60 * 5)]

            // Add the picture to the pasteboard. Instagram will learn the picture from the pasteboard when it is opened.
            UIPasteboard.basic.setItems([pasteboardItem], choices: pasteboardOptions)

            // Open Instagram.
  , choices: [:], completionHandler: nil)

        } else {
            // Instagram app isn't put in or cannot be opened, pop up an alert
// plist



Leave a Reply