Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically select Instagram in UIDocumentInteractionController or UIActivityViewController

UIDocumentInteractionController and UIActivityViewController both present menus for sharing images out to other networks. After hitting Instagram, you are presented with a nice modal that allows you to post to Instgram without leaving the app. My question is, how do I automatically show that modal without showing the menu?

This app called Sounds does it so I know it's possible, but I can't find any documentation online about how it's done. Here is the current code I have which shows the menu:

    NSString *documentDirectory=[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
    NSString *saveImagePath=[documentDirectory stringByAppendingPathComponent:@"Image.ig"];
    NSData *imageData=UIImagePNGRepresentation(cardImage);
    [imageData writeToFile:saveImagePath atomically:YES];
    NSURL *imageURL=[NSURL fileURLWithPath:saveImagePath];

    UIDocumentInteractionController *docController = [UIDocumentInteractionController interactionControllerWithURL:imageURL];
    docController.UTI = @"com.instagram.exclusivegram";
    docController = [self setupControllerWithURL:imageURL usingDelegate:self];
    [docController presentOpenInMenuFromRect:CGRectMake(1, 1, 1, 1) inView:self.view animated:YES];

Here's the menu: 1

Here's what I want to automatically show:

2]

like image 853
evenodd Avatar asked Feb 11 '26 13:02

evenodd


1 Answers

You're able to use UIActivityViewController to show up Instagram as long there is just an UIImage inside the activity items. It won't show up if you add more items like text, url etc. This is a bad limitation made by Instagram.

Like so:

NSMutableArray *items = [NSMutableArray array];
[items addObject:[UIImage ...]];

// show view
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:items
                                                                             applicationActivities:nil];
[vc presentViewController:activityVC animated:YES completion:nil];
like image 173
Arny Avatar answered Feb 14 '26 04:02

Arny