Skip to content

Instantly share code, notes, and snippets.

@leoiphonedev
Last active July 12, 2017 10:57
Show Gist options
  • Save leoiphonedev/ee1ff232b2fecae54109af51d7cb6ff9 to your computer and use it in GitHub Desktop.
Save leoiphonedev/ee1ff232b2fecae54109af51d7cb6ff9 to your computer and use it in GitHub Desktop.
Share image to instagram using objective C in iOS app development
UIImage *instaImage = [UIImage imageNamed:@"imagetoShare.png"];
NSString* imagePath = [NSString stringWithFormat:@"%@/image.igo",[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES) lastObject]];
[[NSFileManager defaultManager] removeItemAtPath:imagePath error:nil];
[UIImagePNGRepresentation(instaImage) writeToFile:imagePath atomically:YES];
UIDocumentInteractionController *_docController = [UIDocumentInteractionController interactionControllerWithURL:
[NSURL fileURLWithPath:imagePath]];
_docController.UTI = @"com.instagram.exclusivegram";
[_docController presentOpenInMenuFromRect:self.view.frame inView:self.view animated:YES];
@Sushobhitbuiltbyblank
Copy link

this code show error - *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UIDocumentInteractionController has gone away prematurely!'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment