【问题标题】:How to differentiate actions selected for `UIDocumentInteractionController` "Open in" menu如何区分为“UIDocumentInteractionController”“打开方式”菜单选择的操作
【发布时间】:2015-02-23 11:50:19
【问题描述】:

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

但是,我需要区分菜单中的一些操作。这是因为例如 Instagram 只接受方形图像,并且在我将图像提供给 instagram 之前需要进行预处理。 (Instagram 工程师应该从裁剪屏幕而不是过滤器屏幕启动应用程序!@#!$)否则 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];

【问题讨论】:

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


    【解决方案1】:

    你需要实现委托的方法。

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

    【讨论】:

    • 只有在点击“在应用程序中打开”时才会调用该函数。你有分享和行动扩展的解决方案吗?
    猜你喜欢
    • 2014-03-05
    • 1970-01-01
    • 2011-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-26
    • 2014-11-28
    相关资源
    最近更新 更多