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
Xamarin iOS post image to Instagram
Change
Url = NSUrl.FromFilename(path)
to
Url = new NSUrl(path,false)
The second way is pointing to the correct file path not the file name .
Change
controller.PresentOpenInMenu(CoreGraphics.CGRect.Empty, view, true);
to
controller.PresentOptionsMenu(UIScreen.MainScreen.Bounds, (UIApplication.SharedApplication.Delegate as AppDelegate).Window, true);
Show
UIDocumentInteractionController
inside current Window and set the proper frame.
UIDocumentInteractionController share via Instagram (and ONLY Instagram)
Turns out to get the doc controller to only open in Instagram you just save your png or jpg file in format ".igo" file type extension, (Maybe stands for Instagram-Only?)
Changed the third line of code in my code to read this instead:
NSString *saveImagePath=[documentDirectory stringByAppendingPathComponent:@"Image.igo"];
(With "igo")
and then it worked! :)
Related Topics
Errortype' Is Not Convertible to 'Nserror'
How to Execute a Function in a Uiviewcontroller Through a Swiftui Button
Automatically Change Cell Height Based on Content - Swift
Start/Stop Image View Rotation Animations
Differrence Between Closure and Function as Argument in Swift
How to Set Cmutablepointer<Objcbool> to False in Swift
Xcode 6 Swift Wkwebview Keyboard Settings
Fill Uiview with Color Based on Percentage
iOS Notification Content Extension: Add Buttons in Storyboard and Handle the Click Action
Receipt Validation on iOS In-App-Purchase Returns Multiple Transaction
Split String into Array of Arrays
How to Hide API Keys in Github for iOS (Swift) Projects
Using Cloud Code with the Parse Server and Heroku
Change Title of a Navigation Bar Button Item
Restkit, Coredata and Swift - I Can't Seem to Fetch Results Back Out
How to Get Date from String in Swift 3
Swift Check If 3D Touch Is Possible
Why the Autolayout Is Not Updated If I Use Ibdesignable File When I Run the App