12

I use the following code in my iOS app to use Instagram iPhone hooks to post a photo to Instagram. I only want the "Open In..." menu to have Instagram app, no other apps. But in my case Camera+ also shows up. How can I restrict to Instagram?

Also, can I directly open Instagram instead of showing Open In menu?

NSURL *instagramURL = [NSURL URLWithString:@"instagram://app"];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
    //imageToUpload is a file path with .ig file extension
    self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:imageToUpload]];
    self.documentInteractionController.UTI = @"com.instagram.photo";
    self.documentInteractionController.annotation = [NSDictionary dictionaryWithObject:@"my caption" forKey:@"InstagramCaption"];
    [self.documentInteractionController presentOpenInMenuFromBarButtonItem:self.exportBarButtonItem animated:YES];
}
AmaltasCoder
  • 1,123
  • 3
  • 17
  • 35

5 Answers5

12

BTW Instagram added an exclusive file extention (ig) and UTI (com.instagram.exclusivegram) for this. It still opens the Open with... menu but the only option is Instagram.

More info here: https://instagram.com/developer/mobile-sharing/iphone-hooks/

Zachary Orr
  • 1,724
  • 1
  • 15
  • 25
JoshOiknine
  • 470
  • 5
  • 15
  • 2
    I already tried this UTI(com.instagram.exclusivegram) but it still shows other apps installed on my device in open in... Is there any other wayout for this? – Manthan Jun 11 '13 at 04:19
  • 3
    Other apps caught on to the ig extensions. Try saving your image file with an igo extension and use the UTI.If you are still having an issue can you post some code? – JoshOiknine Jun 11 '13 at 13:21
  • You can see my code here [http://stackoverflow.com/questions/16954810/sharing-image-on-instagram-in-ios/16955128#16955128]. I made a change in my code after you said imagename=[NSString stringWithFormat:@"ff.igo"]; and self.dic.UTI = @"com.instagram.exclusivegram" but still I am having problem. Please help if you know. – Manthan Jun 11 '13 at 13:53
  • 2
    ^ how did you solve your problem? I am using the igo extension but other apps hook into that now, too. – n13 Oct 08 '14 at 15:04
  • 1
    @Manthan, would you please let us know? – Zoltán Sep 15 '15 at 11:18
  • 1
    @pallzoltan You can check my ans on this link http://stackoverflow.com/questions/16954810/sharing-image-on-instagram-in-ios/16955128#16955128]. – Manthan Oct 12 '15 at 06:53
8

You can get the solution from this link.

  1. Save image with the .igo extension instead of .ig. This is the "exclusive" version of the filetype.

  2. Create a UIDocumentInteractionController, then assign the value com.instagram.exclusivegram to the property UTI.

  3. Present your UIDocumentInteractionController with presentOpenInMenuFromRect:inView:animated.

sudo make install
  • 5,629
  • 3
  • 36
  • 48
nahung89
  • 7,745
  • 3
  • 38
  • 40
4

This worked for me, do it like this and you will have only Instagram as the exclusive app to open your image.

    NSString *documentDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
    // *.igo is exclusive to instagram
    NSString *saveImagePath = [documentDirectory stringByAppendingPathComponent:@"Image.igo"];
    NSData *imageData = UIImagePNGRepresentation(filteredImage);
    [imageData writeToFile:saveImagePath atomically:YES];

    NSURL *imageURL=[NSURL fileURLWithPath:saveImagePath];

    _docController=[[UIDocumentInteractionController alloc]init];
    _docController.delegate=self;
    _docController.UTI=@"com.instagram.photo";
    [_docController setURL:imageURL];
    _docController.annotation=[NSDictionary dictionaryWithObjectsAndKeys:@"#yourHashTagGoesHere",@"InstagramCaption", nil];
    [_docController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
user2421700
  • 149
  • 8
0
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.

Fahim Parkar
  • 30,974
  • 45
  • 160
  • 276
utkal patel
  • 1,321
  • 1
  • 15
  • 24
0

To answer only your first question: you may probably be able to restrict the "Open in ..." menu to just showing Instagram for your device (by deleting the Camera+ App, for example), but you won't be able to restrict users that install your app to their devices. And that's because the iPhone recognizes which applications are able to open a specific kind of files and it automatically show every one that does.

  • This is quite outdated, see @JoshOiknine [answer](http://stackoverflow.com/a/9815885/269753). Also, the second question is the most interesting IMO. – Ricardo Sanchez-Saez Jul 31 '14 at 16:09