do you think is it possible add a code in an application (xcode) that allows print the screen of ipad, or send it to the mac
问问题
2354 次
2 回答
1
#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
,
使用此代码,我可以在路径中打印文件,如何打印我的屏幕而不是路径中已经存在的文件?
于 2011-01-23T13:40:18.327 回答
0
当然可以,但只能来自您自己的应用程序。您不能发送其他应用程序的屏幕截图。
于 2011-01-19T19:18:40.877 回答