How to Share an Image on Instagram in Ios

How to share an image on Instagram in iOS?

Finally I got the answer. you can not directly post an image on instagram. You have to rediredt your image with UIDocumentInteractionController.

@property (nonatomic, retain) UIDocumentInteractionController *dic;    

CGRect rect = CGRectMake(0 ,0 , 0, 0);
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIGraphicsEndImageContext();
NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/test.igo"];

NSURL *igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:@"file://%@", jpgPath]];
self.dic.UTI = @"com.instagram.photo";
self.dic = [self setupControllerWithURL:igImageHookFile usingDelegate:self];
self.dic=[UIDocumentInteractionController interactionControllerWithURL:igImageHookFile];
[self.dic presentOpenInMenuFromRect: rect inView: self.view animated: YES ];


- (UIDocumentInteractionController *) setupControllerWithURL: (NSURL*) fileURL usingDelegate: (id ) interactionDelegate {
UIDocumentInteractionController *interactionController = [UIDocumentInteractionController interactionControllerWithURL: fileURL];
interactionController.delegate = interactionDelegate;
return interactionController;
}

NOTE : once you redirect to instagram app you can not back to your app. you have to open your app again

Download source from here

Sharing Image on instagram in ios

self.documentInteractionController = [self setupControllerWithURL:imgurl usingDelegate:self];

self.documentInteractionController=[UIDocumentInteractionController interactionControllerWithURL:imgurl];

self.documentInteractionController.UTI = @"com.instagram.exclusivegram";

Use this code in same sequence . Here documentInteractionController is object of UIDocumentInteractionController.just for your knowledge. you will get instagram only in "open in" window.

Save your image with igo extension instead of ig.

By this you will only get instagram option in your "Open in" Menu.

Or if you want to open directly instagram when you press the button you can pass the direct url of the app and it will lead you to the native instagram app.

Hope it helps you.

Instagram - share image, text and url via iOS app : swift

Instagram had removed pushing custom captions to their app while sharing photos at one point, check this post.

I also understand, according to the Instagram iPhone Hooks page, that you can pass a photo only to the "Select A Filter" Instagram screen, which is before you set a caption. I'm sorry, but I don't think Instagram supports custom captions.



Related Topics



Leave a reply



Submit