Created
July 24, 2016 06:11
-
-
Save maximbilan/41599d412efcf99cefaa5f558d1f2c38 to your computer and use it in GitHub Desktop.
iOS Instagram Wall Post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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