如何区分为“UIDocumentInteractionController”选择的操作“在”菜单中打开

时间:2015-02-23 11:50:20

标签: ios objective-c instagram social-networking uidocumentinteraction

我正在尝试使用UIDocumentInteractionController为我的应用中存在的图片实现轻松共享。使用下面我正在使用的代码,一切看起来都很好。 (图像可以转发到whatsapp,viber,instagram。图像可以保存到相机胶卷等等)

open in and options sheet

但是,我需要区分菜单中的一些操作。这是因为例如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];

1 个答案:

答案 0 :(得分:0)

您需要实现委托的方法。

- (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];

   }
}