0

与 Air Print 争吵不按按钮做任何事情,我试图从屏幕上打印文件(我第一次实现这个)

我已经添加了UIPrintInteractionControllerDelegatein .h

.m 连接了我的按钮,该按钮已被检查为正常工作

按钮处理程序代码:

 NSString *path = [[NSBundle mainBundle] pathForResource:@"mylocalhtmlfile" ofType:@"HTML"];
NSData *dataFromPath = [NSData dataWithContentsOfFile:path];

UIPrintInteractionController *printController = [UIPrintInteractionController sharedPrintController];

if(printController && [UIPrintInteractionController canPrintData:dataFromPath]) {

    printController.delegate = self;

    UIPrintInfo *printInfo = [UIPrintInfo printInfo];
    printInfo.outputType = UIPrintInfoOutputGeneral;
    printInfo.jobName = [path lastPathComponent];
    printInfo.duplex = UIPrintInfoDuplexLongEdge;
    printController.printInfo = printInfo;
    printController.showsPageRange = YES;
    printController.printingItem = dataFromPath;

    void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
        if (!completed && error) {
            NSLog(@"FAILED! due to error in domain %@ with error code %u", error.domain, error.code);
        }
    };

    [printController presentAnimated:YES completionHandler:completionHandler];

}

除非文件类型设置为png

4

0 回答 0