2014-10-17 1 views
1

Я пытаюсь представить экземпляр UIPrintInteractionController для использования AirPrint для печати изображения. Сначала казалось, что ничего не происходит, но внутри метода делегата printInteractionControllerDidPresentPrinterOptions: Я использую self.presentedViewController, чтобы получить информацию о предполагаемом «представленном» контролере взаимодействия с печатью. Оказывается, он имеет ширину 19.000 и высоту 0,000 ... Не похоже, что есть способ получить доступ к viewcontroller, прежде чем он будет представлен на самом деле, поскольку он полностью автогенерируется в рамках, и я не был способный успешно модифицировать свою кадровую презентацию. Кто-нибудь еще сталкивается с этой проблемой и/или обнаруживает обход?iOS 8 Контроллер взаимодействия печати имеет 0 высоту на iPad

- (void)printBadgeImage:(UIImage *)image { 

    UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController]; 

    UIPrintInfo *printInfo = [UIPrintInfo printInfo]; 
    printInfo.outputType = UIPrintInfoOutputGeneral; 
    printInfo.jobName = BADGE_PRINT_JOB; 
    printInfo.duplex = UIPrintInfoDuplexLongEdge; 
    pic.printInfo = printInfo; 
    pic.printingItem = image; 
    pic.delegate = self; 

    UIPrintInteractionCompletionHandler completionHandler = 
    ^(UIPrintInteractionController *printController, 
     BOOL completed, 
     NSError *error) { 

     if (completed) { 

      NSLog(@"Print job completed"); 

     } else if (!completed && error) { 

      NSLog(@"Print job error"); 
      NSString *errorString = [NSString stringWithFormat:@"An error occured while printing: %@", error]; 
      UIAlertView *alert = [[DOSimpleAlertView alloc] initWithTitle:@"Error" 
                    message:errorString]; 

      [alert show]; 

     } else { 

      NSLog(@"Print job incomplete without error"); 
     } 
    }; 

    [pic presentFromRect:self.view.frame 
        inView:self.view 
       animated:YES 
     completionHandler:completionHandler]; 

} 

- (void)printInteractionControllerDidPresentPrinterOptions:(UIPrintInteractionController *)printInteractionController { 

    NSLog(@"Did present"); 
    // following printed <UIPrintInteractionController: 0x145d1a30> 
    NSLog(@"The Print Interaction Controller: %@", printInteractionController); 
    // following printed <UINavigationController: 0x145d3840> 
    NSLog(@"The presented view: %@", self.presentedViewController); 
    UIViewController *presented = self.presentedViewController; 
    // following printed 19.000000 
    NSLog(@"Presented view width: %f", presented.view.frame.size.width); 
    // following printed 0.000000 
    NSLog(@"Presented view height: %f", presented.view.frame.size.height); 
    // following printed 0.000000 
    NSLog(@"Presented view x: %f", presented.view.frame.origin.x); 
    // following printed 0.000000 
    NSLog(@"Presented view y: %f", presented.view.frame.origin.y); 

ответ

0

У меня есть приложение, которое печатает изображение, но я не смотрел код в течение долгого времени. Но вот рекламный ролик, надеюсь, что это поможет.

NSData *moneyData = UIImageJPEGRepresentation(image, 1.0); 
UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController]; 
if(pic && [UIPrintInteractionController canPrintData: moneyData]) { 

    pic.delegate = self; 

    UIPrintInfo *printInfo = [UIPrintInfo printInfo]; 
    printInfo.outputType = UIPrintInfoOutputGeneral; 
    printInfo.jobName = @"MONEY"; 
    printInfo.duplex = UIPrintInfoDuplexLongEdge; 
    pic.printInfo = printInfo; 
    pic.showsPageRange = YES; 
    pic.printingItem = moneyData; 

    [pic presentFromBarButtonItem:self.printButton animated:YES completionHandler:nil]; 
} 

Если я помню, что есть что-то особенное о том, как вы его представляете. Возможно, вы захотите попробовать элемент с кнопкой, как у меня.