Fabio
Fabio

Reputation: 251

UIDocumentInteractionController doesn't show up

I am trying to present a UIDocumentInteractionController from a navigation controller, when the user selects a file from the tableView.

The interactionControllerWithURL returns NO and the delegate method documentInteractionControllerViewControllerForPreview is never called and the documentInteraction controller does not appear.

The following code is executed when the user selects an item in table:

    NSURL *fileURL;
    fileURL = (NSURL *)[[DataMng sharedMng] getFileInFolder:self.navigationItem.title atRow:indexPath.row type:type];

    if (self.docInteractionController == nil){
        self.docInteractionController = [UIDocumentInteractionController interactionControllerWithURL:fileURL];
        if (!self.docInteractionController) {
            NSLog(@"Selected a file with estension not supported for visualization");
            return;
        }
        self.docInteractionController.delegate = self;
    }else{
        self.docInteractionController.URL = fileURL;
    }

    if(! [self.docInteractionController presentPreviewAnimated:YES]){
        NSLog(@"ERROR in presenting preview");
    }

The delegate controller (self) conforms with UIDocumentInteractionControllerDelegate protocol and is a navigation controller inside a Tabbar controller.

Any ideas will be welcome

Upvotes: 4

Views: 8016

Answers (3)

Tester
Tester

Reputation: 49

you use these methods to show UIDocumentInteractionController:-

-(UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller

{
    return [[[[UIApplication sharedApplication] delegate]window]rootViewController];

}

-(void)documentInteractionControllerDidEndPreview:    (UIDocumentInteractionController *)controller 

{

    self.navigationController.navigationBarHidden = YES;

}

Upvotes: 2

Fabio
Fabio

Reputation: 251

I answer my own question:

the form I was launching the docInteractionController was correct, the problem was in the file url, which lack the correct extension (.pdf in my case) and in the controller UTI, which must of the extended form (com.adobe.pdf).

Once correctly set the preview was displayed without problems.

Upvotes: 9

Ananth
Ananth

Reputation: 845

if(! [self.docInteractionController presentPreviewAnimated:YES]){
        NSLog(@"ERROR in presenting preview");
    }

Think, this is not the right way to present document interactionController. Try setting the below code

CGRect rect = CGRectMake(0, 0, 0, 0);
[self.docInteractionController presentOpenInMenuFromRect:rect inView:self.view animated:YES];

Hope this helps you.

Upvotes: 0

Related Questions