Dismissing of UIPrintInteractionController
Asked Answered
L

4

37

I'm using UIPrintInteractionController presenting it from rect.

UIPrintInteractionController *controller = [UIPrintInteractionController sharedPrintController];
// than set printing settings
...
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    [controller presentFromRect:rect inView:view animated:YES completionHandler:completionHandler];

Than I set number of pages (>1) and select a printer. Before devices rotation I call

[controller dismissAnimated:animated];

according to Xcode documentation: You should dismiss the printing options when they are presented in a sheet or animated from a rectangle and the user changes the orientation of the device.

When I present UIPrintInteractionController after rotation, the number of printing copies is set back to 1 (as in initial view), whereas printer remains selected. Ivar _copies of UIPrintInfo is private, so I can't get it and store during rotation.

How can I restore the number of printing pages after rotation?

Laundress answered 5/11, 2012 at 15:27 Comment(7)
why you dismissing it on rotation?Paraphernalia
@Paraphernalia because Apple recommends to do it in description of dismissAnimated: method of UIPrintInteractionController class. "You should dismiss the printing options when they are presented in a sheet or animated from a rectangle and the user changes the orientation of the device." and "You should then present the printing options again once the new orientation takes effect."Laundress
Here's a link to UIPrintInteractionController class.Laundress
Ever figure out an answer to this?Darkling
@RyanPoolos Still not, have you got any ideas?Laundress
Are you by chance recreating the UIPrintInteractionController upon rotation?Eisenach
@PsychoDad I use only [UIPrintInteractionController sharedPrintController], and it returns the same object every time.Laundress
S
1

Sorry this may seem a bit of an obvious question but have you called it as a delegate?

UIPrintInteractionController *controller = [UIPrintInteractionController sharedPrintController];
controller.delegate = self;
Sanskrit answered 17/7, 2014 at 8:5 Comment(0)
D
1
[printInfo setValue:[NSNumber numberWithInteger:numberFile] forKey:@"copies"]

You can set and set @"copies" of UIPrintInfo

Dubose answered 8/7, 2016 at 4:56 Comment(0)
W
-1
- (void)printImage:(id)sender {
  // Obtain the shared UIPrintInteractionController
  UIPrintInteractionController *controller = [UIPrintInteractionController sharedPrintController];
  if(!controller){
    NSLog(@"Couldn't get shared UIPrintInteractionController!");
    return;
  }

  // We need a completion handler block for printing.
  UIPrintInteractionCompletionHandler completionHandler = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
    if(completed && error)
      NSLog(@"FAILED! due to error in domain %@ with error code %u", error.domain, error.code);
  };

      // Obtain a printInfo so that we can set our printing defaults.
    for(int i=0;i<[paths count];i++)
    {
        NSString *strFilePath = [paths objectAtIndex:i];
        NSLog(@"@ strFilePath is %@", strFilePath);
        NSData *data = [NSData dataWithContentsOfFile:strFilePath];
        if(data)
        {
            image = [UIImage imageWithData:data];
           // [arrayOfImages addObject:image];
               NSLog(@"@ image is %@", image);
            UIPrintInfo *printInfo = [UIPrintInfo printInfo];

            // This application prints photos. UIKit will pick a paper size and print
            // quality appropriate for this content type.
            printInfo.outputType = UIPrintInfoOutputPhoto;
            // The path to the image may or may not be a good name for our print job


            printInfo.jobName = @"PNg";
            NSLog(@"@ imageURL is %@",  printInfo.jobName);
            //  printInfo.jobName


            if(!controller.printingItems && image.size.width > image.size.height)
                printInfo.orientation = UIPrintInfoOrientationLandscape;

            // Use this printInfo for this print job.
            controller.printInfo = printInfo;


            controller.printingItems = nil;

        }
    }





#if DIRECT_SUBMISSION
  // Use the URL of the image asset.
    if(self.imageURL && [UIPrintInteractionController canPrintURL:self.imageURL])
      controller.printingItem = self.imageURL;
#endif

  // If we aren't doing direct submission of the image or for some reason we don't
  // have an ALAsset or URL for our image, we'll draw it instead.
  if(!controller.printingItems){
    // Create an instance of our PrintPhotoPageRenderer class for use as the
    // printPageRenderer for the print job.
    PrintPhotoPageRenderer *pageRenderer = [[PrintPhotoPageRenderer alloc]init];

    pageRenderer.imageToPrint = image;
    controller.printPageRenderer = pageRenderer;
    [pageRenderer release];
  }


  if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    [controller presentFromBarButtonItem:self.printButton animated:YES completionHandler:completionHandler];  // iPad
  }else
    [controller presentAnimated:YES completionHandler:completionHandler];  // iPhone

}
Welkin answered 9/10, 2014 at 9:51 Comment(1)
More explanation please. What have you done? Why? Where are the key lines in your code?Foreconscious
J
-1

If I understand you correctly, what you really need is how to run code before and after orientation changes:

In swift:

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
    super.viewWillTransition(to: size, with: coordinator)

    //code goes here to run before orientation change 

    coordinator.animate(alongsideTransition: nil, completion: {
        _ in

        //code goes here to run after orientation change 
    })

}

Obj C docs:

Jara answered 22/7, 2017 at 13:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.