【问题标题】:Instagram open UTI directlyInstagram直接打开UTI
【发布时间】:2011-06-29 15:48:48
【问题描述】:

我最近偶然发现了以下有趣的功能: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 {

}

【问题讨论】:

  • 我正在我的一个应用程序中使用该代码。我的 iPhone 上同时有 Instagram 和 Dropbox,它们都即将推出。你有没有想过一种方法来限制它只出现在 Instagram 上?
  • 不,还没有... Instagram 几天前发布了他们的应用程序的新版本。从那以后我没有测试过任何东西,但是 iPhone 挂钩上的文档页面没有改变,所以我认为他们没有任何改变。
  • 我们需要他们做出改变,恕我直言......请参阅@AndrewGrant 回答我们为什么需要它:)
  • 我和你有同样的问题,我需要直接从我的应用程序打开我的图片到 Instagram,而不需要任何操作表等......
  • @gotnull 遵循 JoshOiknine 的回答,但在调用 [self setupDocumentControllerWithURL: igImageHookFile] 之前先设置 UTI 参数;它只会显示 Instagram。

标签: objective-c ios ios4 uidocumentinteraction instagram


【解决方案1】:

首先使用 .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,而不是如何在没有用户交互的情况下打开应用程序。
【解决方案2】:

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

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

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

【讨论】:

  • 因此,换句话说,除非他们解析 instagram:// 网址,并且有可能将照片添加为该网址的一部分,否则这是不可能的?因为我注意到,他们确实有一个 URL (instagr.am/developer/iphone-hooks),但在我看来,没有一个参数能满足我的需要。
猜你喜欢
  • 1970-01-01
  • 2012-01-26
  • 1970-01-01
  • 2019-05-05
  • 2022-10-24
  • 2013-09-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多