Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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