Objective c Instagram直接打开UTI

Objective c Instagram直接打开UTI,objective-c,ios,ios4,uidocumentinteraction,instagram,Objective C,Ios,Ios4,Uidocumentinteraction,Instagram,我最近偶然发现了以下有趣的功能: 我想知道是否可以通过documentinteractioncontroller立即打开应用程序,而不必显示预览(–PresentPreviewInimated:)或操作表(–PresentOpenMinumeFromRect:inView:animated:)。在我看来,这是唯一的办法,但我可能错过了什么 -(void) saveToInstagram { NSURL *url; UIDocumentInteractionController *

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

我想知道是否可以通过documentinteractioncontroller立即打开应用程序,而不必显示预览(–PresentPreviewInimated:)或操作表(–PresentOpenMinumeFromRect: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 {

}
-(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-306612612);
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)WriteFile:jpgPath原子化:是];
url=[[NSURL alloc]initFileURLWithPath:jpgPath];
dic=[self-setupControllerWithURL:url usingDelegate:self];
[dic PresentOpenMenuFromRect:rect-inView:self.view动画:是];
[保留];
[img释放];
[网址发布];
}
-(UIDocumentInteractionController*)setupControllerWithURL:(NSURL*)fileURL usingDelegate:(id)interactionDelegate{
UIDocumentInteractionController*interactionController=[UIDocumentInteractionController interactionControllerWithURL:fileURL];
interactionController.delegate=interactionDelegate;
返回交互控制器;
}
-(void)DocumentInteractionController将显示打开菜单:(UIDocumentInteractionController*)控制器{
}

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

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

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

  • 首先使用.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];
    

    所以,换句话说,除非他们解析instagram://url,并且有可能将照片添加到该url中,否则这是不可能的?因为我注意到,它们确实有一个URL(),但在我看来,没有一个参数能满足我的需要。我的iPhone上同时安装了Instagram和Dropbox,它们都即将面世。你有没有想过把它限制在只出现在Instagram上?没有,现在还没有。。。Instagram在几天前发布了新版本的应用程序。从那以后我没有做过任何测试,但iPhone Hook上的文档页面没有改变,所以我认为他们没有任何改变。我们需要他们做出改变,我想。。。请参阅@AndrewGrant答案了解我们需要它的原因:)我与您有相同的问题,我需要直接从我的应用程序打开我的图像到Instagram,而不需要任何操作表等…@gotnull遵循Joshoikine答案,但在调用[self-setupDocumentControllerWithURL:igImageHookFile]之前先设置UTI参数;它将只显示Instagram。为什么会有投票,这根本不能解决问题。这只是展示了如何在打开的菜单中仅显示Instagram,而不是如何在没有用户交互的情况下打开应用程序。