我正在尝试使用UIDocumentInteractionController
实现对应用程序中存在的图像的轻松共享。使用下面的代码,一切看起来都很好。 (图像可以转发到whatsapp,viber,instagram。图像可以保存到相机胶卷等)
但是,我需要区分菜单中的某些操作。这是因为,例如,Instagram仅接受方形图像,因此在将图像提供给instagram之前需要进行预处理。 (Instagram工程师应从裁剪屏幕启动该应用程序,而不要使用过滤器scren!@#!$。)否则,instagram自动自动裁剪图像的底部或右侧。
那么,您是否认为有办法为不同的菜单项操作提供不同的图像?还是我必须首先呈现一个动作控制器并说“在instagram中打开”,“在休息中打开”?如果其他应用程序(如whatsapp,twitter,facebook)具有唯一的“在” UTI中“打开”,那我就走了。
顺便问一下,您是否知道为什么Facebook没有显示在列表中? (我在编辑/管理列表中查看。它不存在)
NSString *documentDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
//NSString *saveImagePath = [documentDirectory stringByAppendingPathComponent:@"Image.png"];
NSString *saveImagePath = [documentDirectory stringByAppendingPathComponent:@"Image.ig"];
//NSString *saveImagePath = [documentDirectory stringByAppendingPathComponent:@"Image.igo"]; // *.igo is exclusive to instagram
NSData *imageData = UIImagePNGRepresentation(capsObject.capImage);
[imageData writeToFile:saveImagePath atomically:YES];
NSURL *imageURL=[NSURL fileURLWithPath:saveImagePath];
self.docController=[[UIDocumentInteractionController alloc]init];
self.docController.delegate = self;
//self.docController.UTI = @"public.image";
self.docController.UTI = @"com.instagram.photo";
//self.docController.UTI = @"com.instagram.exclusivegram";
[self.docController setURL:imageURL];
//[self.docController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
[self.docController presentOptionsMenuFromRect:CGRectZero inView:self.view animated:YES];
最佳答案
您需要实现委托的方法。
- (void)documentInteractionController:(UIDocumentInteractionController *)controller willBeginSendingToApplication:(NSString *)application{
NSLog(@"Will beginsending to application");
// Detect if the application is instagram
if(![application isEqualToString:@"com.instagram.photo"]){
//Make the custom implementation of your image.
UIImage * iconImage = [self prepareImage];
//save it to documents path
NSString * savePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Image.ig"];
[UIImageJPEGRepresentation(iconImage, 1.0) writeToFile:savePath atomically:YES];
// change the URL of your file
controller.URL=[NSURL fileURLWithPath:savePath];
}
}
关于ios - 如何区分为“UIDocumentInteractionController”“打开于”菜单选择的 Action ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28673149/