skip to Main Content

iOS 14.2, I am not able to share image as described in https://developers.facebook.com/docs/instagram/sharing-to-feed/

I can share same image to any other app from this menu correctly (e.g. telegram)

Code:

func shareToInstagramFeed() {
    let instagramURL = NSURL(string: "instagram://")

    if UIApplication.shared.canOpenURL(instagramURL! as URL) {
        let jpgPath = (NSTemporaryDirectory() as NSString).appendingPathComponent("instagram.ig")
        do {
            try selectedImage.image?.jpegData(compressionQuality: 1)?.write(to: URL(fileURLWithPath: jpgPath), options: .atomic)
        } catch {
            print(error)
        }
        let rect = CGRect.zero
        
        documentInteractionController = UIDocumentInteractionController(url: URL(fileURLWithPath: jpgPath))
        documentInteractionController.delegate = self
        documentInteractionController.uti = "com.instagram.photo"
        documentInteractionController.presentOpenInMenu(from: rect, in: view, animated: true)
    }
}

Share menu:
enter image description here

Instagram error:
enter image description here

2

Answers


  1. I was struggling with this and ended up using the UIActivityViewController and it worked.

     let items = [image]
        let ac = UIActivityViewController(activityItems: items, applicationActivities: nil)
        present(ac, animated: true)
    
    Login or Signup to reply.
  2. With Instagram version of 171.0 this issue is fixed. It’s working but it’s very ugly, you can’t choose story or feed, and you can’t edit photo.

    I believe that in the feature instagram will make this feature better.

    If you need to share just one image you can use this workaround:

    let ac = UIActivityViewController(activityItems: [imageUrl, imageUrl], applicationActivities: nil)
    present(ac, animated: true)
    

    (imageUrl intentionally typed 2 times)
    Then you will get following screen:
    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search