iPad中的UIPrintInteractionController给了我两个警告 [英] UIPrintInteractionController in iPad is giving me two warnings
问题描述
我正在使用代码在我的应用中获取Airprint以将当前视图打印为图像。
弹出Airprint对话框,但在日志屏幕中它显示两个警告:
I am using a code to get Airprint in my app to print the current view as an image. the Airprint dialog pops up but in the log screen it shows me two warnings :
1)警告:调用 - [UIPrintInteractionController presentAnimated:completionHandler: ]在iPad
上找不到PDF标题:找不到`%PDF'。
2) [UIPopoverController_commonPresentPopoverFromRect:
inView:allowedArrowDirections:animated:]:传入此方法的rect必须具有非零的宽度和高度。这将是未来版本中的一个例外。
我已经在网上搜索但发现所有解决方案都提供了常规的rect按钮
I have already searched in the net but found that all solutions provided for regular rect Button
我在这里使用的是一个分段控件,在这种情况下我不知道如何使用这个控件
what I am using here is a segmented control, and I don't know how to use this control in this situation
这是段控制代码:
- (IBAction)legalSegment:(id)sender {
switch (((UISegmentedControl *)sender).selectedSegmentIndex) {
case 0:
{
[self printItem];
break;
}
}
这是printItem方法:
and this is the printItem method :
-(void)printItem {
CGRect rect = CGRectMake(0, 0, 768, 1004);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[self.view.layer renderInContext:context];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIPrintInteractionController* pic = [UIPrintInteractionController sharedPrintController];
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(img)];
if (pic && [UIPrintInteractionController canPrintData:imageData])
{
pic.delegate = self;
UIPrintInfo* printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputPhoto;
printInfo.jobName = @"PrintingImage";
printInfo.duplex = UIPrintInfoDuplexLongEdge;
pic.printInfo = printInfo;
pic.showsPageRange = YES;
pic.printingItem = imageData;
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);
}
};
[pic presentAnimated:YES completionHandler:completionHandler];
}
}
任何帮助都会很棒。
提前致谢!
any help will be great. Thanks in advance !
推荐答案
在iPad上,您应该使用控制器提供的popover API。它在文档中提到。
On iPad, you should use the popover API provided by the controller. It is mentioned in the documentation.
presentAnimated:completionHandler:
在一张工作表中显示iPhone打印用户界面,可以从屏幕底部向上滑动
动画。
Presents the iPhone printing user interface in a sheet that can be animated to slide up from the bottom of the screen.
presentFromBarButtonItem:animated:completionHandler:
呈现iPad在弹出视图中打印用户界面,可以通过条形按钮项动画
。
Presents the iPad printing user interface in a popover view that can be animated from a bar-button item.
presentFromRect:inView :animated:completionHandler:
在弹出视图中显示iPad打印用户界面,
从视图中的任何区域进行动画处理。
Presents the iPad printing user interface in a popover view that can be animated from any area in a view.
您应该在相应的设备类型上使用正确的方法。
You should use the correct method on the corresponding device type.
if([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
[pic presentFromRect:self.view.frame inView:self.view animated:YES completionHandler:completionHandler];
}
else {
[pic presentAnimated:YES completionHandler:completionHandler];
}
您应该使用适当的参数进行弹出式演示。
You should use appropriate parameters for the popover presentation.
这篇关于iPad中的UIPrintInteractionController给了我两个警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!