ios – SwiftUI Share Instagram Put up

[ad_1]

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

Button {
           InstagramSharingUtils.shareToInstagramFeed( myImage )
         }

//HELPER

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

        // 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 {
                return
            }

            // 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
                return
            }
            
            
            let pasteboardItem = ["com.instagram.photo": 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.
            UIApplication.shared.open(instagramUrl, choices: [:], completionHandler: nil)

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

<key>LSApplicationQueriesSchemes</key>
    <array>
        <string>instagram</string>
        <string>instagram-stories</string>
    </array>

[ad_2]

Leave a Reply