Instagram直接打开UTI

我最近偶然发现了以下有趣的function: Instagram iPhone挂钩

我想知道是否能够立即通过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 { } 

首先用.ig或.igo扩展名而不是.jpg或.jpeg保存JPEG,然后用file://指令创build一个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]; 

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

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

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