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
How to Turn Page Programmatically in Uipageviewcontroller
Looping a Video With Avfoundation Avplayer
How to Use Uivisualeffectview to Blur Image
Add Placeholder Text Inside Uitextview in Swift
How to Debug iOS 8 Extensions With Nslog
How to Take a Full Screen Screenshot in Swift
Wkwebview Equivalent for Uiwebview's Scalespagetofit
Why Is Glreadpixels() Failing in This Code in iOS 6.0
Display Uiviewcontroller as Popup in Iphone
Why Uitableviewautomaticdimension Not Working
How to Programmatically Sense the Iphone Mute Switch
Ineligible Devices Section Appeared in Xcode 6.X.X
How to Validate an E-Mail Address in Swift
How to Use Auto Layout to Move Other Views When a View Is Hidden
Uinavigationbar Hide Back Button Text
Best Way to Check If Uitableviewcell Is Completely Visible