Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 844
Fabio Avatar asked Oct 14 '25 20:10

Fabio


2 Answers

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.

like image 156
Fabio Avatar answered Oct 17 '25 11:10

Fabio


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;

}
like image 20
Tester Avatar answered Oct 17 '25 11:10

Tester



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!