Skip to content

Instantly share code, notes, and snippets.

@maximbilan
Created July 24, 2016 06:11
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maximbilan/41599d412efcf99cefaa5f558d1f2c38 to your computer and use it in GitHub Desktop.
Save maximbilan/41599d412efcf99cefaa5f558d1f2c38 to your computer and use it in GitHub Desktop.
iOS Instagram Wall Post
let image = UIImage(named: "example")
let instagramURL = NSURL(string: "instagram://app")
if UIApplication.sharedApplication().canOpenURL(instagramURL!) {
let documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0]
let saveImagePath = (documentsPath as NSString).stringByAppendingPathComponent("Image.igo")
let imageData = UIImagePNGRepresentation(image!)
do {
try imageData?.writeToFile(saveImagePath, options: NSDataWritingOptions(rawValue: 0))
} catch {
print("Instagram sharing error")
}
let imageURL = NSURL(fileURLWithPath: saveImagePath)
documentInteractionController.URL = imageURL
documentInteractionController.annotation = ["InstagramCaption" : "Testing"]
documentInteractionController.UTI = "com.instagram.exclusivegram"
let bounds = someButton.bounds
if !documentInteractionController.presentOpenInMenuFromRect(bounds, inView: self.view, animated: true) {
print("Instagram not found")
}
}
else {
print("Instagram not found")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment