iPad/iPhone — printing directly to a network printer without airprint popover

后端 未结 3 1286
迷失自我
迷失自我 2021-02-04 17:41

I\'ve developing an iPad/iPhone application that requires that I print out a receipt on a network printer when I finish a transaction. I\'ve managed to get airprint functionalit

相关标签:
3条回答
  • 2021-02-04 18:10

    try this

      - (IBAction)Print:(id)sender {
        [self searchForPrinters];
       }
     - (void) searchForPrinters
      {
    
      if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1)
      {
             UIPrinterPickerController *printPicker = [UIPrinterPickerController   printerPickerControllerWithInitiallySelectedPrinter:nil];
        [printPicker presentAnimated:YES completionHandler:
         ^(UIPrinterPickerController *printerPicker, BOOL userDidSelect,    NSError *error)
             {
             if (userDidSelect)
               {
                 //User selected the item in the UIPrinterPickerController and got the printer details.
    
                 [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:printerPicker.selectedPrinter];
    
                 //Here you will get the printer and printer details.ie,
                 // printerPicker.selectedPrinter, printerPicker.selectedPrinter.displayName, printerPicker.selectedPrinter.URL etc. So you can display the printer name in your label text or button title.
    
                 [btnSettingsPrint setTitle:printerPicker.selectedPrinter.displayName forState:UIControlStateNormal];
    
                 NSURL *printerURL = printerPicker.selectedPrinter.URL;
    
             }
         }];
    }
     }
    
     -(void)printYourItem :(NSData*)data
     {
     if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1)
      {
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        UIPrinter *currentPrinterObj = [UIPrinter printerWithURL:[NSURL URLWithString:[defaults stringForKey:@"YouKeys"]]];
    
        UIPrintInteractionController *controller = [UIPrintInteractionController sharedPrintController];
    
        if(currentPrinterObj)
        {
            [controller printToPrinter:currentPrinterObj completionHandler:^(UIPrintInteractionController *printController, BOOL completed, NSError *error)
             {
                 if(completed)
                 {
                 }
                 else
                 {
                     NSLog(@"FAILED! due to error in domain %@ with error code %u", error.domain, error.code);
                 }
             }];
        }
    }
    }
    
    0 讨论(0)
  • 2021-02-04 18:18

    There is no way to do this using the UIPrintInteractionController class, it is designed to present the user with standard print options, and there is no app store safe way of getting around this.

    0 讨论(0)
  • 2021-02-04 18:21

    There is a way

    #import <BRPtouchPrinterKit/BRPtouchPrinterKit.h> 
    

    BRPtouchPrinterKit is a Framework for Printer Brother more info here http://www.brother.com/product/dev/mobile/ios/

    Is a SDK especially for this type of printer

    0 讨论(0)
提交回复
热议问题