gpt4 book ai didi

objective-c - Instagram直接打开UTI

转载 作者:技术小花猫 更新时间:2023-10-29 10:17:27 27 4
gpt4 key购买 nike

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

}

最佳答案

首先使用 .ig 或 .igo 扩展名保存 JPEG,而不是 .jpg 或 .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];

关于objective-c - Instagram直接打开UTI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6523475/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com