Store AirPrint settings
$10-30 USD
Pagado a la entrega
I am able to select a printer and store it to call and print at a later time. The problem is I also want to be able to store the number of copies and page size too. So, instead of just the UIPrinterPickerController where I can only select the printer itself, I need to implement the UIPrintInfo with it which allows the printer options available and I need to store that in the NSUserDefaults. I've looked everywhere and can't find anything. The code below works perfectly except it only prints to the saved printer. I need to be able to pre-choose the number of copies.
Here is the code to select the printer.
-(IBAction)selectairprint:(id)sender
{
airprintview.hidden=NO;
if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1)
{
UIPrinterPickerController *printPicker = [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:nil];
[printPicker presentFromRect:[url removed, login to view] inView:airprintview animated:YES completionHandler:
^(UIPrinterPickerController *printerPicker, BOOL userDidSelect, NSError *error)
{
airprintview.hidden=YES;
if (userDidSelect)
{
//User selected the item in the UIPrinterPickerController and got the printer details.
[UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:[url removed, login to view]];
NSURL *printerURL = [url removed, login to view];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[printerURL absoluteString] forKey:@"printURL"];
[defaults synchronize];
}
}];
}
}
And here is the code that gets called at a later time.
-(void)printYourItem :(NSData*)data
{
if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1)
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
UIPrinter *currentPrinterObj = [UIPrinter printerWithURL:[NSURL URLWithString:[defaults stringForKey:@"printURL"]]];
UIPrintInteractionController *controller = [UIPrintInteractionController sharedPrintController];
if(currentPrinterObj)
{
[controller printToPrinter:currentPrinterObj completionHandler:^(UIPrintInteractionController *printController, BOOL completed, NSError *error)
{
if(completed)
{
NSLog(@"PRINTED!");
}
else
{
NSLog(@"FAILED! due to error in domain %@ with error code %u", [url removed, login to view], [url removed, login to view]);
}
}];
}
}
}
Nº del proyecto: #13413020