开发者

print iPad screen code

开发者 https://www.devze.com 2023-02-05 08:03 出处:网络
do you think is it possible ad开发者_开发百科d a code inan application (xcode) that allows print the screen of ipad, or send it to the mac #import \"AirPrintingViewController.h\"

do you think is it possible ad开发者_开发百科d a code in an application (xcode) that allows print the screen of ipad, or send it to the mac


#import "AirPrintingViewController.h"

@implementation AirPrintingViewController

-(void)printItem {

    NSString *path = [[NSBundle mainBundle] pathForResource:@"demo" ofType:@"png"];
    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];

    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [btn addTarget:self action:@selector(printItem) forControlEvents:UIControlEventTouchDown];
    [btn setTitle:@"PRINT" forState:UIControlStateNormal];
    btn.frame = CGRectMake(0, 100, 320, 50);
    [self.view addSubview:btn];
}

@end

,

with this code I can print a file in the path, how can I print my screen instead the file already in the path?


Sure, but only from your own apps. You cannot send screenshots of other apps.

0

精彩评论

暂无评论...
验证码 换一张
取 消