ios - 如何区分为 `UIDocumentInteractionController` "Open in"菜单选择的 Action

标签 ios objective-c instagram social-networking uidocumentinteraction

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

open in and options sheet

但是,我需要区分菜单中的某些操作。这是因为例如 Instagram 只接受方形图像,并且在我将图像提供给 instagram 之前需要进行预处理。 (Instagram 工程师应该从裁剪屏幕而不是滤镜屏幕启动应用!@#!$)否则 Instagram 会自动裁剪图像的底部或右侧部分。

那么您认为有没有办法为不同的菜单项操作提供不同的图像?或者我是否必须首先展示一个 Action Controller 并说“在 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];

最佳答案

您需要实现委托(delegate)的方法。

- (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` "Open in"菜单选择的 Action ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28673149/

相关文章:

ios - 一种使用 UIPinchGestureRecognizer UIRotationGestureRecognizer 和 UIPanGestureRecognizer 添加 Instagram 类布局指南的方法?

ios - 我如何在 swift 中为 iphone 应用程序创建全局服务

iphone - 如何将 1 分钟的时间间隔添加到 iPhone 中的 NSDate 对象

ios - 垂直居中 UITextField 的 attributedPlaceholder

android - Instagram 使用 instagram api 从 cordova 构建的 android 应用程序注销以获得授权

android - 像 Instagram 这样的圆形背景文本,ReplacementSpan 不能按要求工作

ios - 转换 ASN。 1 个签名到 IEEE P1363 签名

ios - React native 人脸检测对我不起作用(iOS)

iphone - Youtube 嵌入 html for uiwebview 不工作(在 iOS 4.2 iPhone 3G 上)

ios - NSTimer 启动延迟