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
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.
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With