首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Instagram直接开放UTI

Instagram直接开放UTI
EN

Stack Overflow用户
提问于 2011-06-29 15:48:48
回答 2查看 8.9K关注 0票数 14

我最近偶然发现了以下有趣的特性:Instagram iPhone钩子

我想知道是否能够立即通过documentinteractioncontroller打开应用程序,不需要显示预览(- presentPreviewAnimated:)或操作表(-presentOpenInMenuFromRect:inView:动画:)。在我看来这是唯一的办法,但我可能错过了什么。

代码语言:javascript
复制
-(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 {

}
EN

回答 2

Stack Overflow用户

发布于 2012-03-22 03:17:28

首先用.ig或.igo扩展名保存您的.jpg或.jpeg,然后创建一个带有文件://指令的NSURL。此外,我还使用了.igo扩展和UTI com.instagram.exclusivegram作为Instagram的独占性,但是您可以使用.ig扩展和UTI com.instagram.gram。

例如:

代码语言:javascript
复制
// 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];
票数 5
EN

Stack Overflow用户

发布于 2011-07-16 18:02:09

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

基本上,UIDocumentInteractionController (和这项技术)解决的局限性是:

  1. 不允许应用程序查询或直接启动其他应用程序。
  2. 应用程序通常不能从其他应用程序的沙箱用户目录中打开文件。
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6523475

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档