gpt4 book ai didi

iOS - 收到警告但无法打印

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:04:45 25 4
gpt4 key购买 nike

我正在使用 iOS 5.0.1 开发应用程序。我正在使用以下代码在我的 ipad 应用程序中打印 View 的屏幕截图:

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 *pic, BOOL completed, NSError* error) {
if (!completed && error) {
NSLog(@"Error: %@", error.localizedDescription);
}
};

[pic presentAnimated:YES completionHandler:completionHandler];
}

它不显示打印 View 并抛出以下错误:

WARNING: Calling -[UIPrintInteractionController presentAnimated:completionHandler:] on iPad
failed to find PDF header: `%PDF' not found.
failed to find PDF header: `%PDF' not found.
failed to find PDF header: `%PDF' not found.
failed to find PDF header: `%PDF' not found.

最佳答案

我通过以下与ipad相关的方法解决了这个问题

- (BOOL)presentFromRect:(CGRect)rect inView:(UIView *)view animated:(BOOL)animated completionHandler:(UIPrintInteractionCompletionHandler)completion;    // iPad
- (BOOL)presentFromBarButtonItem:(UIBarButtonItem *)item animated:(BOOL)animated completionHandler:(UIPrintInteractionCompletionHandler)completion; // iPad

关于iOS - 收到警告但无法打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8699145/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com