Skip to content

Instantly share code, notes, and snippets.

@anvarazizov
Created December 9, 2015 14:40
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 anvarazizov/ae47502ca9964955ddaf to your computer and use it in GitHub Desktop.
Save anvarazizov/ae47502ca9964955ddaf to your computer and use it in GitHub Desktop.
- (void)shareImageToInstagram:(UIImage *)image inView:(UIView *)view
{
NSURL * instagramURL = [NSURL URLWithString:@"instagram://"];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL])
{
NSString * documentDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
NSString * saveImagePath = [documentDirectory stringByAppendingPathComponent:@"Image.igo"];
NSData * imageData = UIImagePNGRepresentation(image);
[imageData writeToFile:saveImagePath atomically:YES];
NSURL * imageURL = [NSURL fileURLWithPath:saveImagePath];
self.docController = [UIDocumentInteractionController interactionControllerWithURL:imageURL];
self.docController.delegate = self;
self.docController.UTI = kInstagramUTI;
[self.docController presentOpenInMenuFromRect:CGRectMake(1, 1, 1, 1) inView:view animated:YES];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment