Skip to content

Instantly share code, notes, and snippets.

@leoiphonedev
Last active April 11, 2018 17:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leoiphonedev/4720f6e0c71c307415c754d13e6a442e to your computer and use it in GitHub Desktop.
Save leoiphonedev/4720f6e0c71c307415c754d13e6a442e to your computer and use it in GitHub Desktop.
Sharing image to Instagram using Swift language
let image = UIImage(named: "imageToShare")
let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as String
let checkValidation = FileManager.default
let getImagePath = paths.appending("image.igo")
try? checkValidation.removeItem(atPath: getImagePath)
let imageData = UIImageJPEGRepresentation(image!, 1.0)
try? imageData?.write(to: URL.init(fileURLWithPath: getImagePath), options: .atomicWrite)
var documentController : UIDocumentInteractionController!
documentController = UIDocumentInteractionController.init(url: URL.init(fileURLWithPath: getImagePath))
documentController.uti = "com.instagram.exclusivegram"
documentController.presentOptionsMenu(from:self.view.frame, in: self.view, animated: true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment