Skip to content

Instantly share code, notes, and snippets.

@maximbilan
Created July 24, 2016 06:11

Revisions

  1. maximbilan revised this gist Jul 24, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion InstagramWallPost.swift
    Original file line number Diff line number Diff line change
    @@ -20,5 +20,5 @@ if UIApplication.sharedApplication().canOpenURL(instagramURL!) {
    }
    }
    else {
    print("Instagram not found")
    print("Instagram not found")
    }
  2. maximbilan created this gist Jul 24, 2016.
    24 changes: 24 additions & 0 deletions InstagramWallPost.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    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")
    }