| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436 |
- //
- // FunctionTestViewController.m
- // iSales-NPD
- //
- // Created by Ray on 3/15/16.
- // Copyright © 2016 United Software Applications, Inc. All rights reserved.
- //
- #import "FunctionTestViewController.h"
- #import "RAUtils.h"
- #import "AppDelegate.h"
- #import "SignatureViewController.h"
- @interface FunctionTestViewController ()
- @end
- @implementation FunctionTestViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
-
-
-
- self.airPrinterController = [UIPrintInteractionController sharedPrintController];
- }
- - (IBAction)onSignature:(id)sender {
- // SignatureViewController * signvc =[ [UIStoryboard storyboardWithName:@"signature" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"SignatureViewController"];
- // signvc.title = [item_json valueForKey:@"aname"];
- // signvc.indexPath = indexPath;
- // // signvc.delegate = self;
- // CommonEditorCellSignature* cell = (CommonEditorCellSignature*) [self.editorTable cellForRowAtIndexPath:indexPath];
- //
- // signvc.existSignature = cell.imageviewSignature.image ;
- //
- //
- //
- // [self.navigationController pushViewController:signvc animated:true];
- __block UIImage* signimg=nil;
- SignatureViewController * vc =[ [UIStoryboard storyboardWithName:@"signature" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"SignatureViewController"];
- // __weak typeof(self) weakself = self;
- vc.onReturnImg = ^(UIImage* img)
- {
- signimg = img;
-
-
-
- };
-
-
- [self.navigationController pushViewController:vc animated:NO];
- }
- - (void)viewWillAppear:(BOOL)animated
- {
-
- [super viewWillAppear:animated];
- [[self navigationController] setNavigationBarHidden:NO animated:NO];
-
- // self.filename = @"print_test";
-
- // NSData* data =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"I25418359" ofType:@"pdf" ]];
-
- // [self startAirPrintWithData1:data];
- [self testUI];
- }
- -(void)testUI
- {
- // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"waiting" completion:^{
- // dispatch_async(dispatch_get_global_queue(0, 0), ^{
- // sleep(2);
- // dispatch_async(dispatch_get_main_queue(), ^{
- // [waitalert dismissViewControllerAnimated:false completion:^{
- //
- //
- //
- // [RAUtils message_box:@"title" message:@"message" completion:nil];
- // }];
- //
- // });
- // });
- // }];
- }
- - (void)startAirPrintWithData:(id )data
- {
-
-
-
- UIPrintInfo *printInfo = [UIPrintInfo printInfo];
- printInfo.outputType = UIPrintInfoOutputGeneral;
- printInfo.orientation = UIPrintInfoOrientationPortrait;
- printInfo.jobName = @"CoolVisitAirPrint";
- self.airPrinterController.printInfo = printInfo;
- self.airPrinterController.printingItem = data;
- self.airPrinterController.delegate = self;
-
- void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
- if(completed && error)
- DebugLog(@"Printing failed due to error in domain %@ with error code %lu. Localized description: %@, and failure reason: %@", error.domain, (long)error.code, error.localizedDescription, error.localizedFailureReason);
- };
- UIPrinter *airPrinter = [UIPrinter printerWithURL:self.printerURL];///*self.printer;*/
-
-
-
-
- [[UIPrinter printerWithURL:self.printerURL] contactPrinter:^(BOOL available)
- {
- if (available)
- {
-
- [self.airPrinterController printToPrinter:airPrinter completionHandler:completionHandler];
- DebugLog(@"AIRPRINTER AVAILABLE");
- }
- else
- {
- DebugLog(@"AIRPRINTER NOT AVAILABLE");
- }
- }];
-
-
- }
- - (void)startAirPrintWithData1:(id )data
- {
-
-
- // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"preparing print..." completion:^{
- PopWaitAlert* pop = [RAUtils waiting_pop:@"preparing print..." completion:nil];
- UIPrintInteractionController* airPrinterController=[UIPrintInteractionController sharedPrintController];
- UIPrintInfo *printInfo = [UIPrintInfo printInfo];
- printInfo.outputType = UIPrintInfoOutputGeneral;
- printInfo.orientation = UIPrintInfoOrientationPortrait;
- printInfo.jobName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"];
- if(self.filename.length>0)
- printInfo.jobName = self.filename;
- airPrinterController.printInfo = printInfo;
- airPrinterController.printingItem = data;
- airPrinterController.delegate = self;
-
-
- airPrinterController.showsNumberOfCopies=true;
- //10.0开始始终显示
- // airPrinterController.showsPageRange = true;
- airPrinterController.showsPaperSelectionForLoadedPapers=true;
-
- void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
- if(completed && error)
- {
- // DebugLog(@"Printing failed due to error in domain %@ with error code %lu. Localized description: %@, and failure reason: %@", error.domain, (long)error.code, error.localizedDescription, error.localizedFailureReason);
- }
- };
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-
-
- if(appDelegate.printerURL==nil)
- {
- // [waitalert dismissViewControllerAnimated:YES completion:nil];
- [pop hide];
- if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1)
- {
- UIPrinterPickerController *printPicker = [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:nil];
- // [printPicker presentFromBarButtonItem:self.btnSubmitOrder animated:yes completionHandler:
-
-
-
- // [ printPicker presentFromBarButtonItem:self.btnshare animated:YES completionHandler:
-
-
-
- [printPicker presentFromRect:CGRectMake(100, 100, 300, 500) inView:self.view animated:YES completionHandler:
-
-
-
- // [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.
-
-
-
-
- appDelegate.printerURL =printerPicker.selectedPrinter.URL.absoluteString;
-
- [self startAirPrintWithData1:data];
-
- }
- else
- {
- }
- }];
- }
- }
- else
- {
- UIPrinter *airPrinter = [UIPrinter printerWithURL:[NSURL URLWithString:appDelegate.printerURL] ];///*self.printer;*/
- [airPrinter contactPrinter:^(BOOL available)
- {
- // [waitalert dismissViewControllerAnimated:YES completion:nil];
- [pop hide];
-
- if (available&& appDelegate.printerURL.length>0)
- {
-
-
- [airPrinterController printToPrinter:airPrinter completionHandler:completionHandler];
- DebugLog(@"AIRPRINTER AVAILABLE");
- }
- else
- {
- appDelegate.printerURL = nil;
-
-
-
-
- DebugLog(@"AIRPRINTER NOT AVAILABLE");
-
-
-
- if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1)
- {
- UIPrinterPickerController *printPicker = [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:nil];
- // [printPicker presentFromBarButtonItem:self.btnSubmitOrder animated:yes completionHandler:
-
-
-
- // [ printPicker presentFromBarButtonItem:self.btnshare animated:YES completionHandler:
-
-
-
- [printPicker presentFromRect:CGRectMake(100, 100, 300, 500) inView:self.view animated:YES completionHandler:
-
-
-
- // [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.
-
-
-
-
- appDelegate.printerURL =printerPicker.selectedPrinter.URL.absoluteString;
-
- [self startAirPrintWithData:data];
-
- }
- else
- {
- appDelegate.printerURL = nil;
-
-
- }
- }];
- }
- }
- }];
- }
-
-
-
-
-
-
-
- // }];
-
-
-
- }
- //-(void)settingPrinter
- //{
- // UIPrinterPickerController *pickerController =[UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:nil];
- // CGRect rect;
- // UIInterfaceOrientation currentOrientation = [UIApplication sharedApplication].statusBarOrientation;
- // rect = CGRectMake(0, 0, 200, 200);
- // void (^completionHandler)(UIPrinterPickerController *, BOOL, NSError *) = ^(UIPrinterPickerController *printController, BOOL userDidSelect, NSError * err) {
- // if (userDidSelect)
- // {
- // // save the urlString and Printer name, do your UI interactions
- // self.printerurl = pickerController.selectedPrinter.URL.absoluteString;
- // self.printerdisplayName = pickerController.selectedPrinter.displayName;
- // }
- // };
- //
- //
- // [pickerController presentFromRect:self.view.frame inView:self.view animated:YES completionHandler:completionHandler];
- // // [pickerController presentAnimated:YES completionHandler:completionHandler];
- //}
- - (IBAction)OnPrintParamsClick:(id)sender {
-
-
-
- }
- - (void) searchForPrinters
- {
- // For checking the ios version is greater than ios 7.Because skipping the Printing UI is ony in ios8 and later.
- if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1)
- {
- UIPrinterPickerController *printPicker = [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:nil];
-
-
- [printPicker presentFromRect:CGRectMake(0, 0, 300, 500) inView:self.view animated:YES completionHandler:
-
-
- // [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.
-
-
- self.labelPrintername.text =printerPicker.selectedPrinter.displayName;
- // [btnSettingsPrint setTitle:printerPicker.selectedPrinter.displayName forState:UIControlStateNormal];
-
- self.printer = printerPicker.selectedPrinter;
-
- self.printerurl =printerPicker.selectedPrinter.URL.absoluteString;
- self.printerURL = printerPicker.selectedPrinter.URL;
-
- }
- }];
- }
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- - (IBAction)onBackgroundprintClick:(id)sender {
-
- //[self startAirPrintWithImage:[UIImage imageNamed:@"notfound_s"]];
- }
- - (IBAction)onPrintersettingClick:(id)sender {
-
- //[self settingPrinter];
-
- [self searchForPrinters];
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- - (UIPrintPaper *)printInteractionController:(UIPrintInteractionController *)printInteractionController choosePaper:(NSArray<UIPrintPaper *> *)paperList
- {
-
- ;
- // (int) width = 29700
- // Printing description of (*( (int *)0x7caa3a40)):
- // (int) height = 42000
- //设置纸张大小
-
-
- for(UIPrintPaper* paper in paperList)
- {
- if (CGSizeEqualToSize(paper.paperSize, CGSizeMake(612, 792)))
- return paper;
- }
- CGSize paperSize = CGSizeMake(612, 792);
- UIPrintPaper * p=[UIPrintPaper bestPaperForPageSize:paperSize withPapersFromArray:paperList];
- return p;
- }
- - (void)printInteractionControllerWillPresentPrinterOptions:(UIPrintInteractionController *)printInteractionController
- {
-
- }
- - (void)printInteractionControllerDidPresentPrinterOptions:(UIPrintInteractionController *)printInteractionController
- {
-
- }
- - (void)printInteractionControllerWillDismissPrinterOptions:(UIPrintInteractionController *)printInteractionController
- {
-
- }
- - (void)printInteractionControllerDidDismissPrinterOptions:(UIPrintInteractionController *)printInteractionController
- {
-
- }
- - (void)printInteractionControllerWillStartJob:(UIPrintInteractionController *)printInteractionController
- {
-
- }
- - (void)printInteractionControllerDidFinishJob:(UIPrintInteractionController *)printInteractionController
- {
-
- }
- @end
|