1

in my application I manage to post an image to Instagram through a Document Interaction Controller. This one shows also options for sharing on Dropbox, whatsapp, etc.. I don't want these features, I just want Instagram. Is there a way to programmatically click on Instagram button, or to remove other unwanted applications' buttons? Thank you in advance for your answers.

EDIT: Here is the code, with the line containing "com.instagram.exclusivegram" I managed to show only Instagram, Bump and Dropbox. How can I make the last two disappear?

-(void)ShareInstagram
{

    [self storeimage];
    NSURL *instagramURL = [NSURL URLWithString:@"instagram://app"];
    if ([[UIApplication sharedApplication] canOpenURL:instagramURL])
    {

        CGRect rect = CGRectMake(0 ,0 , 612, 612);
        NSString  *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/15717.igo"];

        NSURL *igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:@"file://%@", jpgPath]];
        _dic.UTI = @"com.instagram.exclusivegram";
        _dic.delegate=self;
        _dic = [self setupControllerWithURL:igImageHookFile usingDelegate:self];
        _dic=[UIDocumentInteractionController interactionControllerWithURL:igImageHookFile];
        _dic.delegate=self;
        [_dic presentOpenInMenuFromRect: rect    inView: self.view animated: YES ];

        //  [[UIApplication sharedApplication] openURL:instagramURL];
    }
    else
    {
        //   NSLog(@"instagramImageShare");
        UIAlertView *errorToShare = [[UIAlertView alloc] initWithTitle:@"Instagram unavailable " message:@"You need to install Instagram in your device in order to share this image" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];

        errorToShare.tag=3010;
        [errorToShare show];
    }
}


- (void) storeimage
{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,     NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:@"15717.igo"];
    UIImage *NewImg=[self resizedImage:_imageToTweet inImage:CGRectMake(0, 0, 612, 612) ];
    NSData *imageData = UIImagePNGRepresentation(NewImg);
    [imageData writeToFile:savedImagePath atomically:NO];
}


- (UIDocumentInteractionController *) setupControllerWithURL: (NSURL*) fileURL usingDelegate: (id <UIDocumentInteractionControllerDelegate>) interactionDelegate
{
    UIDocumentInteractionController *interactionController = [UIDocumentInteractionController interactionControllerWithURL:fileURL];
    interactionController.delegate = self;

    return interactionController;
}
vokilam
  • 10,153
  • 3
  • 45
  • 56
charles
  • 713
  • 1
  • 6
  • 16
  • The whole point of using a `UIDocumentInteractionController` is to the let user decide what to do. If you only want Instragram, use a different solution. Do some searching here. There are plenty of existing topic on posting directly to Instagram. – rmaddy Mar 03 '14 at 16:24
  • I didn't find anything about direct posting. Can you help me with some links? Thank you. – charles Mar 03 '14 at 17:52
  • @charles, Did you find solution to show only Instagram there? – Abhishek Aug 11 '14 at 12:17
  • 1
    @rmaddy there are no other solutions other than using `UIDocumentInteractionController`, stop misdirecting people. – OpenUserX03 Apr 15 '16 at 04:44

1 Answers1

2

The method setupControllerWithURL:usingDelegate overwrites properties of _dic instance variable set above.

These lines has no effect:

_dic.UTI = @"com.instagram.exclusivegram";
_dic.delegate=self;

First instantiate UIDocumentInteractionController, then set its properties:

NSURL *igImageHookFile = [NSURL URLWithString:[NSString stringWithFormat:@"file://%@", jpgPath]];
_dic = [UIDocumentInteractionController interactionControllerWithURL:igImageHookFile];
_dic.UTI = @"com.instagram.exclusivegram";
_dic.delegate = self;

[_dic presentOpenInMenuFromRect:rect inView:self.view animated:YES];
vokilam
  • 10,153
  • 3
  • 45
  • 56
  • Is there any way to test this in simulator or do you need to do it on your phone? Is there any documentation on the user flow for these features? IG dev site is lacking in this regard. – noobsmcgoobs May 28 '14 at 00:07