Instagram open UTI directly
Asked Answered
C

2

14

I recently stumbled upon the following interesting feature: Instagram iPhone Hooks

I was wondering if one is able to open an app through the documentinteractioncontroller immediately, WITHOUT having to show a preview (– presentPreviewAnimated:) or an action sheet (– presentOpenInMenuFromRect:inView:animated:). Seems to me that it's the only way, but I might be missing something.

-(void) saveToInstagram {
    NSURL *url;
    UIDocumentInteractionController *dic;
    CGRect rect = CGRectMake(0 ,0 , 0, 0);
    UIImage *i = imageView.image;
    CGRect cropRect = CGRectMake(i.size.width - 306 ,i.size.height - 306 , 612, 612);
    NSString  *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Test.ig"];
    CGImageRef imageRef = CGImageCreateWithImageInRect([imageView.image CGImage], cropRect);
    UIImage *img = [[UIImage alloc] initWithCGImage:imageRef];
    CGImageRelease(imageRef);

    [UIImageJPEGRepresentation(img, 1.0) writeToFile:jpgPath atomically:YES];
    url = [[NSURL alloc] initFileURLWithPath:jpgPath];
    dic = [self setupControllerWithURL:url usingDelegate:self];
    [dic presentOpenInMenuFromRect:rect inView:self.view animated:YES];
    [dic retain];
    [img release];
    [url release];
}

- (UIDocumentInteractionController *) setupControllerWithURL: (NSURL*) fileURL usingDelegate: (id <UIDocumentInteractionControllerDelegate>) interactionDelegate {

    UIDocumentInteractionController *interactionController = [UIDocumentInteractionController interactionControllerWithURL: fileURL];
    interactionController.delegate = interactionDelegate;

    return interactionController;
}

- (void)documentInteractionControllerWillPresentOpenInMenu:(UIDocumentInteractionController *)controller {

}
Certified answered 29/6, 2011 at 15:48 Comment(7)
I'm using the code in one of my applications. I have both Instagram and Dropbox on my iPhone and they're both coming up. Did you ever figure out a way to limit it to Instagram appearing only?Faultfinder
Nope still haven't... Instagram released a new version of their app a few days ago though. I haven't tested anything since then, but the documentation-page on iPhone hooks hasn't changed, so I don't think anyhting has changed on their part.Certified
And we need a change on their part, imho... See the @AndrewGrant answer as to why we need it :)Certified
I have the same issue as you , I need open my image directly from my app to Instagram without any Action sheet and etc ...Slumber
Did you ever find anything? I need to do the same thing. I've seen other apps that open Instagram with an image and without showing a UIDocumentInteractionController. Anyone?Applegate
no, but I stopped looking. So there might be a way...Certified
@Faultfinder Follow JoshOiknine answer BUT set UTI parameter first before calling [self setupDocumentControllerWithURL: igImageHookFile]; It will show only Instagram.Rosewater
H
5

First save your JPEG with a .ig or .igo extension instead of .jpg or .jpeg then create a NSURL with a file:// directive. Also I used the .igo extension and the UTI com.instagram.exclusivegram for exclusivity to Instagram but you can use the .ig extension and the UTI com.instagram.gram

For Example:

// URL TO THE IMAGE FOR THE DOCUMENT INTERACTION
NSURL *igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:@"file://%@", jpgPath]];

docInteractionController.UTI = @"com.instagram.exclusivegram";
[self setupDocumentControllerWithURL:igImageHookFile];

// OPEN THE HOOK
[docInteractionController presentOpenInMenuFromRect:self.frame inView:self animated:YES];
Headless answered 22/3, 2012 at 3:17 Comment(1)
Why are there upvotes, this doesn't address the question at all. This just shows how to display only Instagram in the menu that opens, not how to open the app without user interaction.Sachsse
G
2

The only way to do it would be if Instagram registers a custom URL handler (e.g. igram://) and can accept data either as part of that URL (e.g. base64 encoded) or via the pasteboard.

Basically the limitations that UIDocumentInteractionController (and this technique) workaround are:

  1. Apps are not allowed to query for or directly launch other apps.
  2. Apps cannot generally open files from the sandboxed user directory of other apps.
Gobelin answered 16/7, 2011 at 18:2 Comment(1)
So, in other words, it's not possible unless they parse the instagram:// url, and have a possibility to add the photo as a part of that url? Because I've noticed, that they do have a URL (instagr.am/developer/iphone-hooks), but it seems to me none of the parameters give me what I need.Certified

© 2022 - 2024 — McMap. All rights reserved.