4

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.

Now with UIDocumentInteractionController I need to rename these files back to their original name or they will not get recognized correctly.

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.

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?

gamma
  • 1,902
  • 1
  • 20
  • 40
  • 1
    This might be too late but, you can create a hard link using -[NSFileManager linkItemAtPath:toPath:error:] so you don't have to rename your cached file. The hard link can be called something readable that the UIDocumentInteractionController can recognize and the cached file will remain as is. See: https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/nsfilemanager_Class/Reference/Reference.html#//apple_ref/occ/instm/NSFileManager/linkItemAtPath:toPath:error: – Tony Nov 13 '13 at 08:17
  • Ok, this sounds great. I would still have my cached versions and the link could be recreated at any time - in case two cache files had the same base name. I think this might solve the problem. How about making it into an answer? – gamma Nov 13 '13 at 09:37

1 Answers1

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.

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.

Lewis Gordon
  • 1,711
  • 14
  • 19