How to Share Image in Instagramswift

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.

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 <UIDocumentInteractionControllerDelegate>) 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



Related Topics



Leave a reply



Submit