Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

387
Views
Post To Instagram screen on iOS Swift

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?

enter image description 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)
                }
            }
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

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 🤷‍♂️

But in order to receive a local identifier for your image/video, you must first save the image/video to user's photo library. So the final code would look like this

let videoFileUrl: URL = URL(fileURLWithPath: "path/to/my/video")!
var localId: String?
PHPhotoLibrary.shared().performChanges({
    let request = PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: videoFileUrl)
    localId = request?.placeholderForCreatedAsset?.localIdentifier
}, completionHandler: { success, error in
    // completion handler is called on an arbitrary thread
    // but since you (most likely) will perform some UI stuff
    // you better move everything to the main thread.
    DispatchQueue.main.async {
        guard error == nil else {
            // handle error
            return
        }
        guard let localId = localId else {
            // highly unlikely that it'll be nil,
            // but you should handle this error just in case
            return
        }

        let url = URL(string: "instagram://library?LocalIdentifier=\(localId)")!
        guard UIApplication.shared.canOpenURL(url) else {
            // handle this error
            return
        }
        UIApplication.shared.open(url, options: [:], completionHandler: nil)
    }
})
over 4 years ago · Santiago Trujillo Report

0

  1. assume that your image is "png"
  2. assume that you allowed "instagram-stories" in your info.plist (key LSApplicationQueriesSchemes)
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!