Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MrFusion

macrumors 6502a
Original poster
Jun 8, 2005
613
0
West-Europe
So I figured out how to use UIPrintInteractionController with a custom UIPrintPageRenderer (subclass). That is working fine but now I want to print from the print button shown by UIActivityViewController. This part is confusing and the documentation is rather lacking. :(

I expected to see the print options (as with UIPrintInteractionController), but I only see the completionHandler result of UIActivityViewController. Nothing is printed.

Am I suppose to show the UIPrintInteractionController myself in the completionHandler?
But the API says "Upon the completion of an activity, or the dismissal of the activity view controller, the view controller’s completion block is executed." So this should run after printing has completed.

And also if I have to show the printing options myself, then why don't I have to do the same thing for mail? I get the "compose mail view" when selecting mail from the UIActivityViewController.

Also the UIActivityViewController only shows the print icon if I return a UISimpleTextPrintFormatter in activityViewControllerPlaceholderItem: but I want to use my own pageRenderer.

Code:
UIActivityViewController *activityView = [[UIActivityViewController alloc] initWithActivityItems:@[dummy<MyActivityItem>Object]
         applicationActivities:nil];

        [activityView setCompletionHandler:^(NSString *activityType, BOOL completed){
		NSLog(@"complete");
	}];

	[self presentViewController:activityView
					   animated:YES
					 completion:nil];

and the
Code:
MyActivityItem : UIActivityItemProvider <UIActivityItemSource>
subclass

Code:
-(id) activityViewControllerPlaceholderItem:(UIActivityViewController *)activityViewController
{
	NSString *textToShare = @"self.note.note";
	
        //not that this is printing anyway, but I also want to use my own printPageRenderer
	UISimpleTextPrintFormatter *printData = [[UISimpleTextPrintFormatter alloc]
											 initWithText:textToShare]; 
	
	return printData; //now the print item shows up
    return [[UIImage alloc] init]; //
}


-(id) item
{
	NSLog(@"prepare item");
        //do stuff here to prepare the actual item
	NSLog(@"item ready");
	return @"activity item";
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.