应用程序崩溃将UIImage转换为PDF

时间:2022-09-25 16:47:41

Apple rejected my app with this report:

Apple拒绝了我的应用程序:

http://nopaste.me/paste/173567898450806a3c774c4

http://nopaste.me/paste/173567898450806a3c774c4

I cannot reproduce using the same device and iOS as they mention i.e. iPad 3 iOS6.

我无法使用他们提到的相同设备和iOS重现,即iPad 3 iOS6。

They refer to the functionality that converts image into PDF and email it. I use this block of code to do so:

它们指的是将图像转换为PDF并通过电子邮件发送的功能。我使用这段代码来做到这一点:

-(IBAction)didPressSaveToPDFButton:(id)sender{

   NSMutableData *pdfData = [NSMutableData data];
   UIGraphicsBeginPDFContextToData(pdfData, imageView.bounds, nil);
   UIGraphicsBeginPDFPage();
   CGContextRef pdfContext = UIGraphicsGetCurrentContext();
   [imageView.layer renderInContext:pdfContext];
   UIGraphicsEndPDFContext();

   NSLog(@"PDF");

   MFMailComposeViewController *vc = [[MFMailComposeViewController alloc] init];
   vc.mailComposeDelegate = self;
   [vc setSubject:@"PDF"];
   [vc addAttachmentData:pdfData mimeType:@"application/pdf" fileName:@"mypdf.pdf"];

   [self presentModalViewController:vc animated:YES];
}

Does anybody see what the report points to and/or where the error is? I cannot see what's wrong.

有人看到报告指出的内容和/或错误的位置吗?我看不出有什么问题。

Symbolicated report:

符号报告:

Last Exception Backtrace:
0   CoreFoundation                  0x35e9729e __exceptionPreprocess + 158
1   libobjc.A.dylib                 0x32d1f97a objc_exception_throw + 26
2   UIKit                           0x327e213c -[UIViewController     presentViewController:withTransition:completion:] + 3760
3   UIKit                           0x32904252 -[UIViewController         presentModalViewController:animated:] + 26
4   MyAppName                           0x0009c5a2 -[ViewController didPressSaveToPDFButton:] (ViewController.m:200)
5   UIKit                           0x327e10a8 -[UIApplication sendAction:to:from:forEvent:] + 68
6   UIKit                           0x327e1130 -[UIBarButtonItem(UIInternal) _sendAction:withEvent:] + 116

1 个解决方案

#1


1  

Well since you didn't symbolicate your crash log it's pretty tough to tell what's happening. My guess is that that your pdfContext is coming out nil and you are trying to render your imageView in a layer with a nil context.

好吧,因为你没有象征你的崩溃日志,所以很难分辨出发生了什么。我的猜测是你的pdfContext出来了,你试图在一个带有nil上下文的图层中渲染你的imageView。

I would try

我会尝试

 if (pdfContext) {
   [imageView.layer renderInContext:pdfContext];
 }
 else {
   return;
 }

#1


1  

Well since you didn't symbolicate your crash log it's pretty tough to tell what's happening. My guess is that that your pdfContext is coming out nil and you are trying to render your imageView in a layer with a nil context.

好吧,因为你没有象征你的崩溃日志,所以很难分辨出发生了什么。我的猜测是你的pdfContext出来了,你试图在一个带有nil上下文的图层中渲染你的imageView。

I would try

我会尝试

 if (pdfContext) {
   [imageView.layer renderInContext:pdfContext];
 }
 else {
   return;
 }