【问题标题】:UIDocumentInteractionController: (null) imageUIDocumentInteractionController:(空)图像
【发布时间】:2015-09-28 10:29:41
【问题描述】:

我正在从 API 下载图像并将其保存到设备上的目录中。然后我尝试在它上面使用 UIDocumentInteractionController,传递我刚刚保存的图像的本地路径。

NSURL *url = [NSURL fileURLWithPath: filePath];
UIDocumentInteractionController *interactionController = [UIDocumentInteractionController interactionControllerWithURL: url];
interactionController.delegate = self;
CGRect rect = CGRectMake(0, 0, 300, 300);
[interactionController presentOptionsMenuFromRect:rect inView:self.view animated:YES];

当我通过记录比较两个 NSString 时,我得到的是:

  • [url absoluteString]

    file:///var/mobile/Containers/Data/Application/1121F345-0BCA-4624-8A72-F4CE0D39EAE5/Documents/complaint/1443432747ea3dc39ca0b2f6b5f17abddec1f0e9a439955.png

  • filePath

    /var/mobile/Containers/Data/Application/1121F345-0BCA-4624-8A72-F4CE0D39EAE5/Documents/complaint/1443432747ea3dc39ca0b2f6b5f17abddec1f0e9a439955.png

如您所知,路径是相同的,除了开头的 file:// 或 url 字符串。图像没有损坏,但在从 UIDocumentInteractionController 选择的每个操作(保存图像、将其分配给联系人等)中,都有一个(空)对象而不是图像。 我做错了什么?

编辑:

如果我使用

[interactionController presentPreviewAnimated:YES];

而不是

[interactionController presentOptionsMenuFromRect:rect inView:self.view animated:YES];

并提供委托方法documentInteractionControllerViewControllerForPreview: 图像显示和所有操作工作。 为什么它在与预览一起使用时有效,但没有它时无效?

【问题讨论】:

  • 您是否存储了整个路径?您能展示一下您是如何创建filePath 的吗?
  • 这相当复杂,因为我在我的文档中保留了许多目录(我制作了辅助方法),但 filePath 是正确的:我能够成功地使用它执行UIImage imageWithContentsOfFile。
  • 添加从UIDocumentInteractionController 读取“(null) object 而不是 Image”的代码。
  • 选择“分配给联系人”选项后出现的日志消息。 Couldn't get file size for (null): (null) 。此操作过程中不显示图像。
  • 你找到解决方案了吗?

标签: ios nsurl uidocumentinteraction


【解决方案1】:

我在this question找到了答案。

基本上,UIDocumentInteractionController 在处理所选操作之前已被释放 (ARC)。确保它被保留,我通过为它创建一个strong 属性来做到这一点(strong 是下面示例的默认值)。

@property (nonatomic) UIDocumentInteractionController *interactionController;

【讨论】:

  • 这正是我的问题。谢谢。
猜你喜欢
  • 1970-01-01
  • 2014-10-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多