Tapping on `Add Tags` option dismisses the underlying modal view launched by UIDocumentInteractionController abruptly

Viewed 141

I am using the UIDocumentationInteractionController to show the sharing options for a PDF document. (See image below) Everything is working as expected except for the Add Tags option

document interaction controller screenshot

Tapping on it immediately dismisses the controller modal view instead of showing another popup for selecting the tags.

I also see this error on the console when I perform the above workflow.

DocInteractionTest[7132:5381612] Warning: Attempt to present <_UIRemoteViewController: 0x118003a00> on <UIActivityContentViewController: 0x116000000> whose view is not in the window hierarchy!

I believe that this happens as the modal view gets dismissed before the Add Tags modal is getting added on the view hierarchy stack. However, I am unable to understand why is this happening? Has anyone else also seen this similar issue in the past?

It would also be fine for me to hide that option (Add Tags) but I doubt that is possible since Apple doesn't expose any APIs to do this.

Here is some sample code that I have to launch the document interaction controller modal view (I have only included the relevant parts)

@interface ViewController () < UIDocumentInteractionControllerDelegate>

@property (nonatomic, strong) UIDocumentInteractionController *shareDocumentInteractionController;

@end

@implementation ViewController

- (void) showShareMenu:(id) sender {
    NSURL* url = [NSURL fileURLWithPath:[self getPDFPath]]; // pdf document path on disk
    self.shareDocumentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:url];
    self.shareDocumentInteractionController.delegate = self;
    self.shareDocumentInteractionController.UTI = @"com.adobe.pdf";
    [self.shareDocumentInteractionController presentOpenInMenuFromBarButtonItem:sender animated:YES];
}

@end
1 Answers

It would also be fine for me to hide that option (Add Tags) but I doubt that is possible since Apple doesn't expose any APIs to do this.

With regards to the above comment from me in my question, I happen to stumble upon this apple post which talks about best practices as to where should you save the app documents for your app. Reading this post led me to realize that we can show a different modal menu depending on where we save the PDF document and reference it for the UIDocumentInteractionController.

When I posted the sample code above, I was saving the PDF document in the NSDocumentDirectory. However, changing it to NSCachesDirectory shows me a different menu (without the Show Tags option which is what I want). Also, for my specific use case, saving the PDF document temporarily in the Caches directory is just perfect.

NSArray* paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);

New Modal Menu:

enter image description here

It would be great if someone would still be able to answer why the modal disappears but I am fine with hiding this Show Tags option for now.

Related