Post To Instagram screen on iOS Swift

2020-07-18 04:55发布

问题:

I am trying to make sharing from my app to Instagram easy. And what I want is to get to the screen that is depicted on the screenshot below. I've tried instagram-stories://share deeplink and I've read thorugh all these docs: https://developers.facebook.com/docs/instagram/sharing-to-stories/

However, whatever I do, when the url scheme action fires it goes directly into sharing the image into the story. What am I missing here?

Here is my code excerpt:

           if let image = image {
                guard let urlScheme = URL(string: "instagram-stories://share"),
                    let imageData = image.pngData() else {
                    return
                }

                if UIApplication.shared.canOpenURL(urlScheme) {
                    let pasterboardItems = [["com.instagram.sharedSticker.backgroundImage": imageData]]
                    let pasterboardOptions = [UIPasteboard.OptionsKey.expirationDate: Date().addingTimeInterval(60*5)]

                    UIPasteboard.general.setItems(pasterboardItems, options: pasterboardOptions)

                    UIApplication.shared.open(urlScheme, options: [:], completionHandler: nil)
                }
            }

回答1:

  1. assume that your image is "png"
  2. assume that you allowed "instagram-stories" in your info.plist (key LSApplicationQueriesSchemes)


回答2:

What you need to do is to open Instagram app using the following url:
instagram://library?LocalIdentifier= and pass as a parameter PHAsset.localIdentifier.
For some reason this hook isn't listed anywhere in the documentation