UIDocumentInteractionController share via Instagram (and ONLY Instagram)

6.3k views Asked by At

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];

2

There are 2 answers

7
Albert Renshaw On BEST ANSWER

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

1
naresh kolindala On

Lower version of iOS 13:

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

After iOS 13:

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