[IOS 开发] 关于ios打印(AirPrint)

导入 UIPrintInteractionController 类

在.h中实现它的代理Delegate <UIPrintInteractionControllerDelegate>


例子:

UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
    
    if  (pic) {
        
	pic.delegate = self;
		
        UIPrintInfo *printInfo = [UIPrintInfo printInfo];
        printInfo.outputType = UIPrintInfoOutputGeneral;
        printInfo.jobName = @"111";
        printInfo.duplex = UIPrintInfoDuplexLongEdge;
        pic.printInfo = printInfo;
        pic.showsPageRange = YES;
        //可以是多张图片
        pic.printingItems = dataArr;
        
        
		void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) =^(UIPrintInteractionController *pic, BOOL completed, NSError *error) {
			
			if (!completed && error)
				NSLog(@"FAILED! due to error in domain %@ with error code %u",
					  error.domain, error.code);
		};
        
        if (iPad) {
            [pic presentFromRect:sender.frame inView:self.window animated:YES completionHandler:completionHandler];
        }else
        {
            [pic presentAnimated:YES completionHandler:completionHandler];
            
        }
    }



版权声明:本文为u010130947原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。