UIDocumentInteractionController share via Instagram (and ONLY Instagram)
Asked Answered
K

2

5

When I use UIDocumentInteractionController to allow users to share via Instagram, it does work, it brings up the option for "open with" and "Instagram" as one of the options... the problem is that it also displays many other apps like "Facebook" and "Twitter"...


Is there any way I can make it only give the option of opening in the instagram app?


Instagram claims there is a way to do this: http://instagram.com/developer/iphone-hooks/ but they mention this:
"Alternatively, if you want to show only Instagram in the application list (instead of Instagram plus any other public/jpeg-conforming apps) you can specify the extension class igo, which is of type com.instagram.exclusivegram."

but I honestly have no clue what this part means, "extension class igo"

My code:

UIImage *imageToUse = [UIImage imageNamed:@"imageToShare.png"];
NSString *documentDirectory=[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
NSString *saveImagePath=[documentDirectory stringByAppendingPathComponent:@"Image.ig"];
NSData *imageData=UIImagePNGRepresentation(imageToUse);
[imageData writeToFile:saveImagePath atomically:YES];
NSURL *imageURL=[NSURL fileURLWithPath:saveImagePath];
docController = [UIDocumentInteractionController interactionControllerWithURL:imageURL];
docController.delegate = self;
docController.annotation = [NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"This is the users caption that will be displayed in Instagram"], @"InstagramCaption", nil];
docController.UTI = @"com.instagram.exclusivegram";
[docController presentOpenInMenuFromRect:CGRectMake(1, 1, 1, 1) inView:self.view animated:YES];

Kenyatta answered 9/11, 2014 at 21:6 Comment(1)
show this error - *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: UIDocumentInteractionController has gone away prematurely! ios 10.3Visualize
K
11

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! :)

Kenyatta answered 9/11, 2014 at 21:18 Comment(7)
Do you know how to remove "save to dropbox" option with *.igo files?Jeramey
It seems the brilliant folks at dropbox decided to include .igo files in their app for who knows what reason, so now they have broken the instagram-only feature for everyone else. #ThanksDropBoxKenyatta
.igo no longer seems to work in iOS9, it still returns many options.Guidebook
@Guidebook I dont think it's an iOS9 thing, I think a bunch of other apps started adapting .igo so that they could show up when you search for that file format. It's a very lame and invasive tactic if you ask me.Kenyatta
@AlbertRenshaw booo! that is lame. Hopefully Instagram will make a proper posting API or adjust their extension.Guidebook
@Guidebook .igo does work on IOS9 , Use [documentController presentOpenInMenuFromRect] instead of [presentOptionsMenuFromRect:CGRectZero] - OpenIn shows only apps that can open .igoGambrinus
@Gambrinus Very good! I'll test this in my next app and edit it into my answer :DKenyatta
S
4

Lower version of iOS 13:

NSString *saveImagePath=[documentDirectory stringByAppendingPathComponent:@"Image.igo"];

After iOS 13:

NSString *saveImagePath=[documentDirectory stringByAppendingPathComponent:@"Image.ig"];
Sussna answered 9/3, 2020 at 10:14 Comment(1)
Good one! ThanksCountenance

© 2022 - 2024 — McMap. All rights reserved.