Reputation: 681
Whenever I try show the UIDocumentInteractionController
with the method presentOptionsMenuFromRect
no file is attached in the opening app and I get this in the console:
Couldn't get file size for (null): (null)
But if I test with presentOpenInMenuFromRect
it works perfectly fine. I also use presentPreviewAnimated
with its delegates and this works too. Also tested successfully switching to an UIActivityViewController. The file I try to open is a PDF stored in the local documents directory
let documentInteractionController = UIDocumentInteractionController.init(URL: url)
documentInteractionController.presentOptionsMenuFromRect(self.view.bounds, inView: self.view, animated: true)
Xcode: 7.3.1 (Swift) iOS: 9.3 tested with simulator and device, deployment target is 8.0
Thanks
Upvotes: 0
Views: 1052
Reputation: 26
This happens because in your code, the UIDocumentInteractionController instance might be being released by reaching the end of a function, while it's needed to let the other app handle the file properly after selecting an option from the menu.
To avoid this problem, we need to store a strong reference to our document interaction controller in a place that will exist for the lifetime of the object's owner (i.e. a global variable) in order to keep it alive.
Note: Apparently, this behavior does not occur with some of the options from the Open In menu nor by sharing with AirDrop.
Upvotes: 1