UIDocumentInteractionController not displaying a print option

I have code to display a document as follows:

documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:self.thisUrl]; NSString *pathExtension = [self.thisUrl pathExtension]; if (pathExtension) { NSString *UTI = (__bridge NSString*)UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)(pathExtension), NULL); if (UTI) { documentInteractionController.UTI = UTI; } } documentInteractionController.delegate = self; [documentInteractionController presentOptionsMenuFromBarButtonItem:shareButton animated:YES]; 

When the options menu is displayed, it displays a list of applications that can open the document (such as a message), as well as a list of actions below.

The options menu displays list actions other than the menu shown, for example, in the Mail application.

The main difference is that the Mail application shows the "print" option, while there are no options in my menu. How to get the options menu to show the print option?

The options menu shown in my app

The options menu shown in mail

EDIT: I did another test where I implemented the methods:

 - (BOOL)documentInteractionController:(UIDocumentInteractionController *)controller canPerformAction:(SEL)action { return YES; } - (BOOL)documentInteractionController:(UIDocumentInteractionController *)controller performAction:(SEL)action { return YES; // or NO, doesn't matter } 

This affected the display of the “print”, “copy” and “save to camera” actions in a pop-up window. Nothing happened when I clicked on them, possibly because I didn’t use -performAction . I also get a warning in the console log about using deprecated methods.

It was a step back in some way because I could no longer print some documents that could print correctly with the document interaction controller before adding these methods.

+7
ios uidocumentinteraction
source share
2 answers

Apple recommends using the UIActivityViewController . You can easily achieve this with this. However, the Print option is only available if the type of shared content supports printing. You can see the list of supported actions by data types here.

 - (IBAction)shareButton:(UIBarButtonItem *)sender { NSString *textToShare = @"Text to share"; NSURL *myWebContent = [NSURL URLWithString:@"http://yourpath.com/yourfile.pdf"]; // set your printable file here! NSData *myData = [NSData dataWithContentsOfURL:myWebContent]; NSArray *objectsToShare = @[textToShare, myData]; UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil]; //Add exclusions here NSArray *excludeActivities = @[UIActivityTypeAirDrop, UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll, UIActivityTypeAddToReadingList, UIActivityTypePostToFlickr, UIActivityTypePostToVimeo]; activityVC.excludedActivityTypes = excludeActivities; [self presentViewController:activityVC animated:YES completion:nil]; } 
+2
source share

I got this working using the QuickLook framework. I do not know why the "print" option sometimes does not appear for the document interaction controller, but then again, apparantly no one else does.

The QuickLook framework supports previewing certain types of documents, but not all, so I left in my previous view controller and document interaction controller for these unsupported types.

Below is a snippet of my working code.

 @interface PreviewItemDataSource () @property (nonatomic, retain) NSURL* item; @end @implementation PreviewItemDataSource @synthesize item=_item; +(PreviewItemDataSource*)dataSourceWithItem:(NSURL*)item { PreviewItemDataSource *source = [[PreviewItemDataSource alloc] init]; source.item = item; return source; } -(NSInteger) numberOfPreviewItemsInPreviewController:(QLPreviewController*)controller { return 1; } - (id<QLPreviewItem>) previewController:(QLPreviewController*)controller previewItemAtIndex:(NSInteger)index { return self.item; } @end @interface AppDelegate () @property (nonatomic, retain) PreviewItemDataSource *dataSource; @end ... -(void) openExternalFile:(NSString*) filePath withDelegate:(id<ChildBrowserDelegate>)delegate { if ([filePath length] == 0) return; NSURL *item = [NSURL URLWithString:filePath]; if (item && [QLPreviewController canPreviewItem:item]) { [self openQuickLookForItem:item]; } else { // previous method unchanged } } - (void) openQuickLookForItem:(NSURL*)item { QLPreviewController *controller = [[QLPreviewController alloc] init]; PreviewItemDataSource *dataSource = [PreviewItemDataSource dataSourceWithItem:item]; controller.dataSource = dataSource; controller.modalPresentationStyle = UIModalPresentationFullScreen; [controller setCurrentPreviewItemIndex:0]; [self.viewController presentViewController:controller animated:YES completion:nil]; self.dataSource = dataSource; } 
+2
source share

All Articles