我最近偶然发现了以下有趣的特性:Instagram iPhone钩子
我想知道是否能够立即通过documentinteractioncontroller打开应用程序,不需要显示预览(- 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 {
}发布于 2012-03-22 03:17:28
首先用.ig或.igo扩展名保存您的.jpg或.jpeg,然后创建一个带有文件://指令的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];发布于 2011-07-16 18:02:09
唯一的方法是Instagram注册一个自定义的URL处理程序(例如igram://),并且可以接受数据作为URL的一部分(例如base64编码)或通过pasteboard接受数据。
基本上,UIDocumentInteractionController (和这项技术)解决的局限性是:
https://stackoverflow.com/questions/6523475
复制相似问题