的嘗試這個
- (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);
}
}];
}
}
}
你有沒有找到這個問題的任何解決方案? – 2011-06-15 14:55:01
我也在尋找同樣的功能。有誰知道這一點。 – Rajashekar 2011-07-26 09:08:08
@Rajashekar最後,你有沒有找到任何方法來做到這一點? – 2014-09-22 09:45:15