Tho*_*asM 14 objective-c ios4 ios uidocumentinteraction instagram
我最近偶然发现了以下有趣的功能: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 {
}
Run Code Online (Sandbox Code Playgroud)
首先使用.ig或.igo扩展名而不是.jpg或.jpeg保存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];
Run Code Online (Sandbox Code Playgroud)
唯一的方法是 Instagram 注册一个自定义 URL 处理程序(例如 igram://),并且可以接受数据作为该 URL 的一部分(例如 base64 编码)或通过粘贴板。
基本上,UIDocumentInteractionController(和此技术)解决方法的限制是:
| 归档时间: |
|
| 查看次数: |
8713 次 |
| 最近记录: |