【发布时间】: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