I'm using the UIDocumentInteractionController
with a temporary file that resides in my cache after having downloaded it. I'm using a quite simple class that delivers md5-cache
file names (ext = cache) to my app and the downloaded file is in this format. The reason is to have files locally and to only download them once (a session). Since the cache names are in a uniform format I can easily clean them up.
我使用的是UIDocumentInteractionController,它有一个临时文件,在下载后驻留在缓存中。我正在使用一个非常简单的类,它将md5缓存文件名(ext = cache)传递给我的应用程序,下载的文件就是这种格式。原因是在本地有文件,并且只下载一次(会话)。由于缓存名称采用统一格式,所以我可以轻松地清理它们。
Now with UIDocumentInteractionController
I need to rename these files back to their original name or they will not get recognized correctly.
现在使用UIDocumentInteractionController,我需要将这些文件重命名为它们的原始名称,否则它们不会被正确识别。
When the UIDocumentInteractionController
finishes handing off the file I thought to move the file back to its cache file name. The problem is, the method: - documentInteractionController:didEndSendingToApplication:
never gets called - though the delegate is set correctly.
当UIDocumentInteractionController完成分发文件时,我想把文件移回它的缓存文件名。问题是,方法:- documentInteractionController:didEndSendingToApplication:永远不会被调用——尽管委托设置正确。
How I basically set up the controller:
我是如何设置控制器的
interactionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:temporaryFile]];
interactionController.delegate = self;
interactionController.annotation = [cacheURLString lastPathComponent]; // original name to move back to
Any suggestions on how to correctly find out that a file has been handed over to another application / or the UIDocumentInteractionController
has been dismissed?
关于如何正确地发现一个文件已被移交给另一个应用程序/或UIDocumentInteractionController已被驳回,有什么建议吗?
1 个解决方案
#1
3
I found that documentInteractionController:didEndSendingToApplication:
is called if the document is sent to another application, but isn't called when sending the document via email (and possibly other built in functions like AirDrop, copy, print, etc.). This seems like a bug to me, but there it is.
我发现如果文档被发送到另一个应用程序,那么就会调用documentInteractionController:didEndSendingToApplication:,但在通过电子邮件发送文档时不会调用它(也可能是其他内置的函数,如AirDrop、copy、print等)。这对我来说像是一个bug,但它确实存在。
Tony's answer in the comments worked for me - use [[NSFileManager defaultManager] linkItemAtURL:toURL:error]
to link the source file to a temporary file and pass the temporary file to the controller. This isn't taking up a lot of additional space and the temporary link will be removed after a certain amount of time.
Tony在评论中的回答对我起了作用——使用[[[NSFileManager defaultManager] linkItemAtURL:toURL:error]将源文件链接到临时文件,并将临时文件传递给控制器。这并不会占用很多额外的空间,在一段时间后临时链接将被删除。
#1
3
I found that documentInteractionController:didEndSendingToApplication:
is called if the document is sent to another application, but isn't called when sending the document via email (and possibly other built in functions like AirDrop, copy, print, etc.). This seems like a bug to me, but there it is.
我发现如果文档被发送到另一个应用程序,那么就会调用documentInteractionController:didEndSendingToApplication:,但在通过电子邮件发送文档时不会调用它(也可能是其他内置的函数,如AirDrop、copy、print等)。这对我来说像是一个bug,但它确实存在。
Tony's answer in the comments worked for me - use [[NSFileManager defaultManager] linkItemAtURL:toURL:error]
to link the source file to a temporary file and pass the temporary file to the controller. This isn't taking up a lot of additional space and the temporary link will be removed after a certain amount of time.
Tony在评论中的回答对我起了作用——使用[[[NSFileManager defaultManager] linkItemAtURL:toURL:error]将源文件链接到临时文件,并将临时文件传递给控制器。这并不会占用很多额外的空间,在一段时间后临时链接将被删除。