Instagram直接打开UTI

Tho*_*asM 14 objective-c ios4 ios uidocumentinteraction instagram

我最近偶然发现了以下有趣的功能:Instagram iPhone Hooks

我想知道是否能够立即通过documentinteractioncontroller打开应用程序,无需显示预览( - presentPreviewAnimated :)或操作表( - presentOpenInMenuFromRect:inView:animated :).在我看来,这是唯一的方式,但我可能会遗漏一些东西.

-(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 {

}
Run Code Online (Sandbox Code Playgroud)

Jos*_*ine 5

首先使用.ig或.igo扩展名而不是.jpg或.jpeg保存JPEG,然后使用file://指令创建NSURL.我还使用了.igo扩展名和UTI com.instagram.exclusivegram来获得Instagram的排他性,但你可以使用.ig扩展名和UTI com.instagram.gram

例如:

// 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];
Run Code Online (Sandbox Code Playgroud)

  • 您通常应该使用`[NSURL fileURLWithPath:]`来表示基于文件的URL ... (2认同)

And*_*ant 2

唯一的方法是 Instagram 注册一个自定义 URL 处理程序(例如 igram://),并且可以接受数据作为该 URL 的一部分(例如 base64 编码)或通过粘贴板。

基本上,UIDocumentInteractionController(和此技术)解决方法的限制是:

  1. 应用程序不允许查询或直接启动其他应用程序。
  2. 应用程序通常无法打开其他应用程序的沙盒用户目录中的文件。

  • 所以,换句话说,除非他们解析 instagram:// url,并且有可能将照片添加为该 url 的一部分,否则这是不可能的?因为我注意到,他们确实有一个 URL (http://instagr.am/developer/iphone-hooks/),但在我看来,没有一个参数能给我我需要的东西。 (2认同)