14

私は最近、次の興味深い機能に出くわしました: Instagram iPhone Hooks

プレビュー (– presentPreviewAnimated:) またはアクション シート (– presentOpenInMenuFromRect:inView:animated:) を表示することなく documentinteractioncontroller を介してアプリをすぐに開くことができるかどうか疑問に思っていました。それが唯一の方法のように思えますが、何かが欠けている可能性があります。

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

}
4

2 に答える 2

5

最初に JPEG を .jpg または .jpeg の代わりに .ig または .igo 拡張子で保存してから、file:// ディレクティブを使用して NSURL を作成します。また、Instagram への排他性のために .igo 拡張子と UTI com.instagram.exclusivegram を使用しましたが、.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];
于 2012-03-22T03:17:28.743 に答える
2

これを行う唯一の方法は、Instagram がカスタム URL ハンドラー (igram:// など) を登録し、その URL の一部 (base64 エンコードなど) またはペーストボードを介してデータを受け入れることができる場合です。

基本的に、UIDocumentInteractionController (およびこの手法) の回避策の制限は次のとおりです。

  1. アプリが他のアプリを照会したり、直接起動したりすることは許可されていません。
  2. アプリは通常、他のアプリのサンドボックス化されたユーザー ディレクトリからファイルを開くことはできません。
于 2011-07-16T18:02:09.517 に答える