【发布时间】: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