Instagram открывает UTI напрямую

Недавно я наткнулся на следующую интересную особенность: Instagram iPhone Hooks

Мне было интересно, можно ли сразу открыть приложение через operatorinteractioncontroller, БЕЗ, чтобы показать предварительный просмотр (- presentPreviewAnimated:) или лист действий (- presentOpenInMenuFromRect: inView: анимированный:), Мне кажется, что это единственный способ, но я могу что-то упустить.

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

}

Ответы

Ответ 1

Сначала сохраните свой JPEG с расширением .ig или .igo вместо .jpg или .jpeg, затем создайте NSURL с директивой file://. Также я использовал расширение .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];

Ответ 2

Единственный способ сделать это - если Instagram регистрирует собственный обработчик URL (например, igram://) и может принимать данные либо как часть этого URL (например, base64 encoded), либо через картотеку.

В основном ограничения, которые могут возникнуть при использовании метода UIDocumentInteractionController (и этой техники):

  • Приложениям не разрешено запрашивать или запускать другие приложения.
  • Приложения обычно не могут открывать файлы из изолированной каталожной папки других приложений.